Split a string by /r/n

Hi, I have a string that looks something like

“Line1\r\n
Line2\r\n
Line3\r\n”

and so on… how do I use the String.split function to separate this into a String array?

Note that the \r\n is in escape characters here to make it easier to read, in my app it is the actual carriage return line feed symbols.

Can’t find a specific API that works in this case or adapt it to this situation

edit: I usually just use lines.Split(“\r\n”) but somehow this is not working. Option strict on disallows implicit conversions from ‘String’ to ‘Char’

Hi,

please Try: yourText.Split(Environment.NewLine.ToArray, StringSplitOptions.RemoveEmptyEntries).

regards
Aditya

9 Likes

use split string activity and in option you can provide Environement.Newline

2 Likes

Try this:

SplitByNewLine.xaml (6.8 KB)

Also note:

  1. The first argument in the method InputStringVariable.Split(argumentAsArray, second argument) should be an ARRAY not a string.

  2. Instead of using “\r\n” (which loses its special meaning inside double quotes), either use vbCr+vbLf or vbNewLine OR as most have suggested, Environment.NewLine

I am now trying to concatenate strings with line breaks instead of splitting them.

I want to create a multi-line delimiter to split a text document.

The overall delimiter looks something like this.

\r\n is the actual carriage return and line feed, they are shown here as escape characters for visualization purposes.

Address\r\n
Line 1\r\n
Line 2\r\n
Line 3\r\n

To create this delimiter, I have to put together two strings.

  1. “Address”
  2. “Line 1\r\nLine2\r\nLine3\r\n”

How do I concatenate the two strings together with the \r\n in the middle? (only one line break)

I tried using Environment.NewLine but I printed this out in a message box, the concatenated result is a two line break.

I tried using vbCrLf etc. but I get the same result as well

It seems like I tried all the options listed (vbNewLine, vbNewLine, vbCrLf, Environment.NewLine) but I can’t get the exact results. I keep getting double line break instead of single line break when I try to print the result in a message box.

What I need is:
Address
Line1
Line2
Line3

What I currently get is:
Address

Line1
Line2
Line3

1 Like

Try below:

image

1 Like

Thank you very much, it’s worked for me!

There’s a vbCrLf constant.