Split string by character and store either side as variables for later use

Hi Guys - I am trying to split an ID : XX_123456 and use either side as stored variables for later use.

I have found great info on how to separate but after that I want to store both as different variables and use them in the process after, which is proving very hard to find the answer to.

I am able to store the “XX” part very easily using XX.ToString.Substring(0,2)

But I want the numbers after as a separate ID.

I have used Test.Split("_"c) in a for each etc which is fine but I can’t seem to store the number separately afterwards. Storing as an array etc but I just want the number as a string.

Many Thanks in advance!

Hi @Kyleb91

try to do it based on regex only numbers you can get it

like \d.+

Thanks
Ashwin S

@Kyleb91,

You can try like this,

strValue is a string datatype variable
which holds the value.

strValue.Substring(strValue.IndexOf("_")+1)

Hi @AshwinS2 - thanks, so you mean return only the numbers to a variable? Makes sense - could you show me how to perhaps?

Hey - so assign: account_ID - accountNKwhich is the variable XX_123456.Substring(accountNK.IndexOf(“_”)+1)

This is giving me an error - Startindex cannot be less than 0, paramter name:startindex?

Any chance you could help me formulate - I’m very confused…

Hi @Kyleb91
Do one thing create a string with ismatch activity and give the regex expression

Thanks
Ashwin S

@Kyleb91,

That’s a fantastic solution! Thanks so much, a lot more simple than other ways.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.