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.
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.
Try to use
string[] strings = yourString.Split(new string[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)
You can use a StringReader
:
var reader = new StringReader(textbox.Text);
string line;
while(null != (line = reader.ReadLine()) {
//...
}