Split string from 10th instance of character in string?

Hey guys I have a string like the example below
“|stuff|stuff|stuff|stuff|stuff|stuff|stuff|stuff|here|stuff|stuff|stuff|stuff|stuff|”

And I need to split it on the 10th instance of “|” so that I can get:
“|stuff|stuff|stuff|stuff|stuff|stuff|stuff|stuff|here”

And I need to be able to target it on the specific instance of this character as I would use this function across mulitple bots. How can you do this is UiPath?

Hi,

Can you try the following?

System.Text.RegularExpressions.Regex.Match(text,"^(\|[^\|]+){9}").Value

Regards,

1 Like

Is there a different code that will specifically target the instance of the pipe character?

The problem with the regex is in the bot its not actually going to say ‘stuff’ its going to have a pretty extensive variety of numbers, letters and various special characters and space characters.

Hi,

Is there a different code that will specifically target the instance of the pipe character?

The following will also work.

String.Join("|",text.Split({"|"c}),0,10)

Regards,

Hey Yoichi, is there a way to then remove that same section from the original string?

So I was able to assign everything before the tenth pipe character to a new variable, but I’d also like to remove everything before the tenth pipe character from the original string as well.

1 Like

Hi,

but I’d also like to remove everything before the tenth pipe character from the original string as well.

How about the following?

String.Join("|",text.Split({"|"c}),10,text.Count(function(x) x="|"c)-10-1)

Regards,

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