Unable to split a string with newLine delimiter?

I made a string variable

a =“this is
new line”

but not able to get split it using new line.
I have tried
a.Split(VbCrLf, StringSplitOptions.NONE)

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

have you tested changing vbCrLf with Environment.NewLine?

@blacksundar

Try these expressions:

a.split(Environment.NewLine.TocharArray)(0) - this is

a.split(Environment.NewLine.TocharArray)(1) - new line

1 Like

Okay. I’ll tell u what I’ve used?
VbCrLf,
VbLf,
Environment.NewLine

Now not able to get the required result.

1 Like

@blacksundar try vbNewLine

Sorry I missed that, I have also used that :wink:

@blacksundar are you splitting using .ToCharArray? Split(vbNewLine.ToCharArray) . Because this is working for me

Hi @blacksundar

try this

a.Split({vbLf},StringSplitOptions.RemoveEmptyEntries)

4 Likes

Hi @blacksundar,

Please try the below syntax and try once.

a.Split(VBNewline.tocharArray, StringSplitOptions.RemoveEmptyEntries)

Regards,
Shiva Karthik

Thank you all. But I’ll post what didn’t work.

can you all please tell me reasons of all?
a.Split({vbCrLf},StringSplitOptions.RemoveEmptyEntries)
a.Split({Environment.NewLine},StringSplitOptions.RemoveEmptyEntries)
a.Split({VbNewline},StringSplitOptions.RemoveEmptyEntries)
a.Split(VBNewline.tocharArray, StringSplitOptions.RemoveEmptyEntries)

what’s difference between
a.Split({vbNewline}, StringSplitOptions.RemoveEmptyEntries)
and
a.Split(vbNewline.ToCharArray, StringSplitOptions.RemoveEmptyEntries)

2 Likes

@blacksundar

Could you please share your Workflow. Will check and update you.

Hi @blacksundar

vbCrLf - when you have both carriage return(Cr) and Line feed(Lf) in the string
vbCr - Only when Carriage return(Cr) in the string
vbLf - Only when Line feed(Lf) in the string

a.Split({vbNewline}, StringSplitOptions.RemoveEmptyEntries)
and
a.Split(vbNewline.ToCharArray, StringSplitOptions.RemoveEmptyEntries)

both function perform same…

after split(u have to use char )

first one assign as char array method {vbNewline}
next one they convert as char array vbNewline.ToCharArray)

so Respected of function u have to mention within the {} otherwise u have to convert as TocharArray()

thanks…

Hi @amaresan

Thank you so much for your time.
I have tested all methods given in this message.

{}, without{} performed different way. 1st one didn’t split using new line, but second one did…

why is it so?

@blacksundar

Split function separates Strings. It receives a string or character delimiter. It parses and separates the source string by separating the parts that come between the delimiter.

@blacksundar

could you share me the code which is not working… i will explain why not working


it’s output is “1”


it’s output is “2”

@blacksundar

I’m not sure may it perform like this. You u are give two method is single {} that will consider always one

if u use two Cr and Lf in curly braces u have to give like this samplestring.split({vbCr,VbLf},StringSplitOptions.RemoveEmptyEntries).Length.ToString

otherwise use tocharArray()

i hope it make clear

Regards
Amaresan.P

2 Likes