Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse user input from a textarea line by line

If I have a variable that contains text information (say taken from a textarea), how can I read the text content held in a string variable line by line?

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

like image 411
Blankman Avatar asked Apr 19 '10 19:04

Blankman


3 Answers

This is an old question but this could help! Personally I use this code to handle all Operating System:

myString.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries)
like image 147
Adriien M Avatar answered Oct 24 '22 19:10

Adriien M


You can use a StringReader:

var reader = new StringReader(textbox.Text);
string line;
while (null != (line = reader.ReadLine())) {
     //...
}
like image 16
SLaks Avatar answered Nov 20 '22 21:11

SLaks


Try to use

string[] strings = yourString.Split(new string[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
like image 8
Hun1Ahpu Avatar answered Nov 20 '22 21:11

Hun1Ahpu