Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String splitting produces different results than expected

Tags:

string

c#

split

alt text

it returns not what i expected. i expected something like:

ab
cab
ab

what am i doing wrong?

like image 250
Varyanica Avatar asked Dec 07 '22 03:12

Varyanica


1 Answers

don't do .ToCharArray()

it will split \r then \n

that why you have empty value

something like this should work

var aa = ("a" & Environment.NewLine & "b" & Environment.NewLine & "c").Split(New String[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);
like image 60
Fredou Avatar answered Dec 09 '22 16:12

Fredou