How Can I split data?


I want to separate the date range data and location data.
How can I do it?

Hi @toto6343

Try the following,

Step 1 : Store the data to a string type variable (OrginalString)

Step 2 : Use assign activity,

LHS : DateRangeString
RHS :
originalString.Substring(0, originalString.IndexOf(“~”))

Step 3 : Use Assign Activity

LHS :
LocationString
RHS originalString.Substring(originalString.IndexOf(“~”) + 1)

Hope this works out well for you.

Thanks,
Gautham.

From your sample data it looks like date range has a fixed number of characters so you can get date range and location by a simple Substring method
Assign original data to string: strOrigString
Then assign date range: strDateRange = strOrigString.Substring(0,21)
This is assuming date range is always 21 characters including the ~ based on the sample.
The assign location: strLocation = strOrigString.Substring(22,strOrigString.Length - 21)
This is because the location will start at the 22nd character and the number of characters would be the original string minus the length of the date range.

Another solution you can do is using Regex, as you know that despite the differences in the text, your data will end up with 2 digits :slight_smile:

.*(?:\d{2})

image

UiPath Assign expression: System.Text.RegularExpressions.Regex.Match("2024.05.04~2024.05.05ThisIsNormalText",".*(?:\d{2})").ToString

image

Also, by using Split.First, and Split.Last, you can get them separated:

image

Hope it helps,

BR,
Ignasi