c# - String.Split for new lines working with string[] but not with char[] -
check code:
string t = @"\nazerty \n\nazerty \n\nazerty \nazerty"; string[] firstmethod = t.split(new char[]{'\n'}, stringsplitoptions.removeemptyentries); string[] secondmethod = t.split(new string[]{@"\n"}, stringsplitoptions.removeemptyentries);
why first method not work , second ???
thx
this isn't working because using verbatim strings, i.e.:
string t = @"\nazerty \n\nazerty \n\nazerty \nazerty";
... equivalent to:
string t = "\\nazerty \\n\\nazerty \\n\\nazerty \\nazerty";
it's wanted following, uses newline characters instead of literal backslash-n:
string t = "\nazerty \n\nazerty \n\nazerty \nazerty";
this "successfully" split on either new[] { "\n" }
or new[] { '\n' }
(but not new[] { @"\n" }
expects backslash-backslash-n).
Comments
Post a Comment