String.split into a string array

I am tying to split a list of items each on a new line. the code i am using is varriable lines default to text.split(“\r\n”)

How ever I am getting an error that "option strict on disallows implicit conversions from ‘string’ to ‘char’. I have tried slapping a toarray and tostring method at the end but I do not understand what that message is referring to

Its all good @tsorrill!

the split command needs a little extra love to make it work.
Hopefully this does the trick :wink:
myString.Split({“\r\n”},system.StringSplitOptions.None)

@tsorrill
Give a try on yourstringvar.Split({Environment.newline},StringSplitOptions.RemoveEmptyEntries)

2 Likes

Hi @tsorrill,

The error message means that the Separator specified is not a Character array. Like @ppr & @Mr_Meeseeks mentioned you can convert the Environment.NewLine to a character array and that should resolve it strVar.Split(Environment.NewLine.ToCharArray,StringSplitOptions.RemoveEmptyEntries)

Regards,
PD

4 Likes

Hey @tsorrill
<Your_String_Var>.Split({Environment.NewLine,"\r\n","\n",vbCrLf, vbLf},System.StringSplitOptions.RemoveEmptyEntries)

Why i prefer this because based on my past experiences due to different text encodings sometime Environment.Newline does not work so if line feed is coming with cariage return den vb consent like vbCrLf and so works there.

Regards…!!
Aksh

I ran into a similar problem with blah.Split(“,”). I had to use blah.Split(","C).

@carlor

can you try this >> blah.Split({“,”},StringSplitOptions.RemoveEmptyEntries).ToList

I had tried it but it gave a compiler error. I went with my option and it worked perfectly. IIFC, I’ve run into this scenario before.

Carlo.

1 Like