Unable to split a string with \r\n\r\n delimiter?

I send outlook mail see the mail.body or mail.headers(“PlainText”), string variable like:

IPS Username = aa\r\n\r\nIPS Password =123\r\n\r\nIPS Username= bb\r\n\r\nIPS Password =456\r\n\r\nIPS Range\r\n =;;;;;;;;;;\r\n\r\n
IPS Username = aa\r\n\r\nIPS Password =123\r\n\r\n

but not able to get split it using \r\n\r\n.
I have tried :
arg.Split("\r\n\r\n", StringSplitOptions.NONE)

not returning two elements indeed returning full string. why ??

IPS Username = aa
IPS Password =123
IPS Username= bb
IPS Password =456
IPS Range =;;;;;;;;;;
IPS Username = aa
IPS Password =123

1 Like

Hello @SihYingChen ,

You can use Matches activity, Try this image

just replace the string you looking for!

Try here :point_right: Regex


“\r\n” are line break characters in Windows (in C# expression). The VB.NET equivalent is vbCrLf or you could also use Environment.NewLine.

arg.Split(Environment.NewLine.ToCharArray, StringSplitOptions.RemoveEmptyEntries)

Alternative two is to use Regex.Split which recognizes “\r\n” as is:

System.Text.RegularExpressions.Regex.Split(arg, "\r\n")

Thanks for your reply. The text I posted includes only the small portion. It contains a list of “IPS xxx” not just the Username and the Password. Do you know better way to split the text by not using fixed term?

Hi ptrobot, I tried your answer by using “\r\n\r\n” (double \r\n), that is how I want my text to be split. However, the code splits also the “\r\n” (single \r\n). Do you know how to avoid splitting the single \r\n? Many thanks for your answer.

Which one did you test? The first one or the second one? The second one should only split where there are “\r\n\r\n” if that’s what you specified.

System.Text.RegularExpressions.Regex.Split(arg, "\r\n\r\n")

Use .split("\r\n\r\n",c)

1 Like

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