How to parse user input from text area line by line

If I have a variable that contains text information (for example, taken from a text field), how can I read the text content contained in a string variable by a string?

The text entered in the text area will have \ n (enter the key) to separate the line.

+5
source share
4 answers

You can use StringReader:

var reader = new StringReader(textbox.Text);
string line;
while (null != (line = reader.ReadLine())) {
     //...
}
+11
source

Try using

string[] strings = yourString.Split(new string[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
+6
source
string[] splitInput = System.Text.RegularExpressions.Regex.Split(
                        InputString, "\r\n");
0

, ! :

myString.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries)
0

All Articles