# Split String dynamically

**URL:** <https://forum.uipath.com/t/split-string-dynamically/63587>\
**Category:** Help\
**Tags:** system, activities\
**Created:** [September 5, 2018, 7:15am UTC](https://forum.uipath.com/t/split-string-dynamically/63587 "2018-09-05T07:15:54Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![sangasangasanga](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sangasangasanga/32/66848_2.png) [@sangasangasanga](https://forum.uipath.com/u/sangasangasanga)\
**Post date:** [September 5, 2018, 7:15am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/1 "2018-09-05T07:15:54Z")

</div>

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](https://global.discourse-cdn.com/uipath/original/3X/7/4/74f0f5f29d9e9d42ea41a08ccab94c58007a51d4.png)  
How to split the after text from 2018 if there is?

Thank you xoxo

---

<div class="post-metadata">

**Author:** ![Manjuts90](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/manjuts90/32/176617_2.png) [@Manjuts90](https://forum.uipath.com/u/Manjuts90)\
**Post date:** [September 5, 2018, 7:36am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/2 "2018-09-05T07:36:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sangasangasanga](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sangasangasanga/32/66848_2.png) [@sangasangasanga](https://forum.uipath.com/u/sangasangasanga)\
**Post date:** [September 5, 2018, 7:40am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/3 "2018-09-05T07:40:27Z")

</div>

@Manjuts90 yup

---

<div class="post-metadata">

**Author:** ![Manjuts90](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/manjuts90/32/176617_2.png) [@Manjuts90](https://forum.uipath.com/u/Manjuts90)\
**Post date:** [September 5, 2018, 7:43am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/4 "2018-09-05T07:43:11Z")

</div>

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

[faketext------------.xaml](https://global.discourse-cdn.com/uipath/original/3X/5/f/5f9a8d9c1cbe4e5c92483964db35b3a6513cb88a.xaml) (11.3 KB)

---

<div class="post-metadata">

**Author:** ![sangasangasanga](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sangasangasanga/32/66848_2.png) [@sangasangasanga](https://forum.uipath.com/u/sangasangasanga)\
**Post date:** [September 5, 2018, 7:55am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/5 "2018-09-05T07:55:16Z")

</div>

@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](#):
>
> How to split the after text from 2018 if there is?

---

<div class="post-metadata">

**Author:** ![Manjuts90](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/manjuts90/32/176617_2.png) [@Manjuts90](https://forum.uipath.com/u/Manjuts90)\
**Post date:** [September 5, 2018, 8:08am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/6 "2018-09-05T08:08:17Z")

</div>

@sangasangasanga is below one is not working?

> [@sangasangasanga](#):
>
> System.Text.RegularExpressions.Regex.Match(date1, “(?\<=2018 )\d+”).ToString

---

<div class="post-metadata">

**Author:** ![sangasangasanga](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sangasangasanga/32/66848_2.png) [@sangasangasanga](https://forum.uipath.com/u/sangasangasanga)\
**Post date:** [September 5, 2018, 8:13am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/7 "2018-09-05T08:13:29Z")

</div>

> [@sangasangasanga](#):
>
> System.Text.RegularExpressions.Regex.Match(date1, “(?\<=2018 )\d+”)

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

> [@sangasangasanga](#):
>
> S|Scale-up|RAM(|Hhh,|SLC:|95%)|01|Apr|2018|to|30|Apr|2018|420|KE(s)

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

---

<div class="post-metadata">

**Author:** ![Manjuts90](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/manjuts90/32/176617_2.png) [@Manjuts90](https://forum.uipath.com/u/Manjuts90)\
**Post date:** [September 5, 2018, 9:35am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/8 "2018-09-05T09:35:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sangasangasanga](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sangasangasanga/32/66848_2.png) [@sangasangasanga](https://forum.uipath.com/u/sangasangasanga)\
**Post date:** [September 5, 2018, 9:41am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/9 "2018-09-05T09:41:32Z")

</div>

@Manjuts90 sorry, maybe I wasn’t clear enough

From this

> [@sangasangasanga](#):
>
> S|Scale-up|RAM(|Hhh,|SLC:|95%)|01|Apr|2018|to|30|Apr|2018|420|KE(s)

Expected Outcome

> [@sangasangasanga](#):
>
> S|Scale-up|RAM(|Hhh,|SLC:|95%)|01|Apr|2018|to|30|Apr|2018

---

<div class="post-metadata">

**Author:** ![Manjuts90](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/manjuts90/32/176617_2.png) [@Manjuts90](https://forum.uipath.com/u/Manjuts90)\
**Post date:** [September 5, 2018, 10:02am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/10 "2018-09-05T10:02:56Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![sangasangasanga](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sangasangasanga/32/66848_2.png) [@sangasangasanga](https://forum.uipath.com/u/sangasangasanga)\
**Post date:** [September 6, 2018, 1:48am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/11 "2018-09-06T01:48:18Z")

</div>

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

> [@Manjuts90](#):
>
> Str.Substring(0,str.IndexOf(“2018”,str.IndexOf(“2018”)+1)+“2018”.Length)

Your code above works for the strings below

> [@sangasangasanga](#):
>
> 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)

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](https://global.discourse-cdn.com/uipath/original/3X/f/7/f742b04d6002563fe5486e9e606202711c1d67a1.png)

---

<div class="post-metadata">

**Author:** ![arivu96](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@arivu96](https://forum.uipath.com/u/arivu96)\
**Post date:** [September 6, 2018, 4:30am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/12 "2018-09-06T04:30:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sangasangasanga](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/sangasangasanga/32/66848_2.png) [@sangasangasanga](https://forum.uipath.com/u/sangasangasanga)\
**Post date:** [September 6, 2018, 5:30am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/13 "2018-09-06T05:30:30Z")

</div>

@arivu96

> [@arivu96](#):
>
> **withoutMoney** variable type and value

It is the input line and it is string

> [@arivu96](#):
>
> |ER1|Date|Downup|(Weekly/Monthly|File)|Apr|2018|336|GA(s)

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)

---

<div class="post-metadata">

**Author:** ![arivu96](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@arivu96](https://forum.uipath.com/u/arivu96)\
**Post date:** [September 6, 2018, 5:58am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/14 "2018-09-06T05:58:46Z")

</div>

> [@sangasangasanga](#):
>
> 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](https://global.discourse-cdn.com/uipath/original/3X/7/8/7834eb2612a190a73d883539113307eaee497405.xaml) (5.8 KB)

Regards,  
Arivu

---

<div class="post-metadata">

**Author:** ![AkshaySandhu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/akshaysandhu/32/77316_2.png) [@AkshaySandhu](https://forum.uipath.com/u/AkshaySandhu)\
**Post date:** [September 6, 2018, 6:28am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/15 "2018-09-06T06:28:10Z")

</div>

@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…

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [October 29, 2018, 9:16am UTC](https://forum.uipath.com/t/split-string-dynamically/63587/16 "2018-10-29T09:16:40Z")

</div>

Closed on October 29, 2018, 9:16am UTC


