Home > Blockchain >  "\n\r" String to Array C#
"\n\r" String to Array C#

Time:05-09

When I do a Reader.ReadToEnd() it returns \n\r , How do I convert that String into array without '\n\r' , Even better, how do I give a signal that \n\r is a new index in the array?

CodePudding user response:

You can use the following:

var array = Reader.ReadToEnd().Split("\r\n", StringSplitOptions.None);

This will remove all the new-line characters from the array and leave what is in between them as seperate elements.

The StringSplitOptions has enum values that determine whether empty (StringSplitOptions.RemoveEmptyEntries) or white-space (StringSplitOptions.TrimEntries) substrings should be omitted.

CodePudding user response:

If your input lines are coming from the OS you run at, you can:

string[] lines = Reader.ReadToEnd().Split(Environment.NewLine, StringSplitOptions.None);

This way you don't care about the environment of you code.

  • Related