String split \n

Hi everyone,
I can’t seem to split a string into an array based on \n. I see that lots of people advide on using the Enviroment.NewLine method, but I can’t get it to work (it says I need to declare Enviroment). The string is extracted from a text file and the content of the text file is ever changing.

You can use

Where strVar is a string variable where you can store Input String


alternatively you can use this, if you have trouble importing the environment class in your projects. (can’t think of a reason why that happens, but hey, lets think out of the box:

Split(StrVar, chr(13))(0)
Split(StrVar, chr(13))(1)
Split(StrVar, chr(13))(2)


lineArray (array of string) = System.text.regularexpressions.regex.split(stringVar, environment.Newline)

use foreach activity to loop over the lines of lineArray

I always get this message, I don’t know what’s wrong.

you;re missing an “n”



Doesn’t seem to work either.

Ok, now it seems to be working, BUT then I don’t understand how to get the single word. I wanted to print out Jack, i created a message box writing Text(0) and it gives me the single letter…

1 Like

do this first @sebastiano_santini

declare variable lineArray ( array of string)

then assign
lineArray = System.text.regularexpressions.regex.split(Text, environment.Newline)

now lineArray(0) will print Jack

1 Like

I can’t get it to work. I’ll attch the workflow so you can see what im doing.

Thanks for the help btw!
Main.xaml (10.8 KB)

Hi @sebastiano_santini,

You can use the “read text file” activity instead of “Use Application”.



1 Like


assign this to lineArray instead, then it should work

lineArray = System.Text.RegularExpressions.Regex.split(in_Text, "\n")

1 Like

I changed from use application to read file text and it worked, no metter if i used environment.newline or “\n”. Do you have any idea why it doesn’t on use application?

1 Like

i guess get text doesnt treat newlines as newlines, read text file does
if your input is a text file just use read text file

1 Like

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