How to split a string on two possible words

I need to get substrings from all text before ánd after two possible words. These words are “at” and “by”.

So when I have the following string:
“Hello this is a text by Piet”

NewVariable1: “Hello this is a text”
NewVariable2: “Piet”

But “by” is sometimes “at”. For this, I can build an if statement of course. But since I already have I few if statements in this bot I hope I can fix this with a regex for example. Does anybody know how to solve this problem? Would really appreciate it!

Hi,

Can you try the following expression?

text.Split({"by","at"},Stringsplitoptions.None)

or

System.Text.RegularExpressions.Regex.Split(text,"by|at")

Regards,

1 Like

I think I tried these a already. Problem is that I cannot assign this array to a string so I have to indicate the first part first on this variable, and then do it again with the last variable, right?

Hi,

You need to set String array(String[]) type variable (let’s say arrString) in left textbox in Assign activity as the following.

arrString = text.Split({"by","at"},Stringsplitoptions.None)

Then, we can get each value like

NewVariable1 = arrString(0)
NewVariable2 = arrString(1)

Regards,

1 Like

That makes sense. Thanks a lot!

1 Like

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