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 ??
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?
Try these expressions:
a.split(Environment.NewLine.TocharArray)(0) - this is
a.split(Environment.NewLine.TocharArray)(1) - new line
Okay. I’ll tell u what I’ve used?
VbCrLf,
VbLf,
Environment.NewLine
Now not able to get the required result.
Sorry I missed that, I have also used that
@blacksundar are you splitting using .ToCharArray? Split(vbNewLine.ToCharArray) . Because this is working for me
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)
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?
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.
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