c# - How to split Environment.NewLine? -
i want count number of lines in text.
below works fine:
int numlines = copytext.split('\n').length - 1;
however, i've been using system.environment.newline
in whole of code , when try:
int numlines = copytext.split(system.environment.newline).length - 1;
it keeps bringing red wriggly line underneath stating cannot convert string char. been trying rectify no luck. have ideas?
to split on newline, can use following:
copytext.split(new string[] { system.environment.newline }, stringsplitoptions.none).length - 1;
here reference overload uses string array.
note system.environment.newline of type system.string
. on windows 2 character string: \r\n
, on unix systems 1 character string: \n
. why cannot use char.
wikipedia has article on newlines: https://en.wikipedia.org/wiki/newline
i recommend reading it.
Comments
Post a Comment