Split String dynamically

Hi, There are some lines which has some text after 2018 but some don’t. I would to split the after text from 2018 from the string. Right now, I am using delimiters and hardcoding it.

E.g
S|social|Service|(Hhh,|1|vCPU|mmm,|95%)|01|Apr|2018|to|30|Apr|2018
S|Social|(Ff,|mmmm)|SlO2345-AB-AC|01|Apr|2018|to|30|Apr|2018
S|Scale-up|vCPU(|Hhh,|SLC:|95%)|01|Apr|2018|to|30|Apr|2018|90|vABC(s)
S|Scale-up|RAM(|Hhh,|SLC:|95%)|01|Apr|2018|to|30|Apr|2018|420|KE(s)

I would like to get the date into a column. What I am doing right now is:

str.LastIndexOf("|", str.LastIndexOf("|") -20)

Which is okay if the after text is not there
the output looks like this:

image
How to split the after text from 2018 if there is?

Thank you xoxo

@sangasangasanga u required 2 dates in each line am i correct.

@Manjuts90 yup

@sangasangasanga Check the workflow below. i considered input is present in text file.

faketext------------.xaml (11.3 KB)

2 Likes

@Manjuts90 Thanks for your effort. It works. But I also want the text after the date. I know how to get it. But I don’t know how to split it from the string.
System.Text.RegularExpressions.Regex.Match(date1, “(?<=2018 )\d+”).ToString
How can I split it.

@sangasangasanga is below one is not working?

It working but it only get the last text after 2018. But idk how to split it from the string

Eg I am getting 420 as a different variable. I want to split the after text from 2018 from the string. So suppose to be S|Scale-up|RAM(|Hhh,|SLC:|95%)|01|Apr|2018|to|30|Apr|2018 as another variable

@sangasangasanga u want output as KE(s) right?

@Manjuts90 sorry, maybe I wasn’t clear enough

From this

Expected Outcome

@sangasangasanga You will get required output from below method

Str.Substring(0,str.IndexOf(“2018”,str.IndexOf(“2018”)+1)+“2018”.Length)

where str is string variable which contains your input line

Hi @Manjuts90 thanks alot bro. I got one more question.

Your code above works for the strings below

But for strings like below, the code is not working. Correct me if I am wrong - your code finds “2018” then the length. The below strings have “2018” too. Then why isn’t it working for below strings?

S|ER1|Date|Downup|(Weekly/Monthly|File)|Apr|2018|336|GA(s)
S|ERl|Date|Downup|(Daily|File)|Apr|2018|193|WE(s)

I also tried to go around for lines like above so that my workflow will continue to run without errors. But it doesnt work either
image

HI @sangasangasanga,

can you tell me the what is the withoutMoney variable type and value?

what is your expected output? from this text “S|ER1|Date|Downup|(Weekly/Monthly|File)|Apr|2018|336|GA(s)”

Regards,
Arivu

@arivu96

It is the input line and it is string

i would like to get |ER1|Date|Downup|(Weekly/Monthly|File)|Apr|2018 frsplitted.

Shoudn’t this code be able to do that?
Str.Substring(0,str.IndexOf(“2018”,str.IndexOf(“2018”)+1)+“2018”.Length)
Example of the lines
S|ERl|Date|Downup|(Weekly/Monthly|File)|Apr|2018|230|GA(s)
S|ERl|Date|Downup|(Daily|File)|Apr|2018|124|WE(s)

"First:"+withoutMoney.Substring(0,withoutMoney.IndexOf("2018")-4)

"Second:"+withoutMoney.Substring(withoutMoney.IndexOf("2018")-4,8)
Main.xaml (5.8 KB)

Regards,
Arivu

1 Like

@sangasangasanga
If I understood you correctly…
below will give all the text before the text “2018”
Left(str,str.Tostring.LastIndexof(“2018”)+4)

e.g

  1. |ER1|Date|Downup|(Weekly/Monthly|File)|Apr|2018 |336|GA(s)
  2. S|Scale-up|RAM(|Hhh,|SLC:|95%)|01|Apr|2018|to|30|Apr|2018 |420|KE(s)

in above bold text will be removed from string
let us know if this works for you…

1 Like