开发者

How to parse user input from a textarea line by line

开发者 https://www.devze.com 2022-12-27 16:03 出处:网络
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?

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.


You can use a StringReader:

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


Try to use

string[] strings = yourString.Split(new string[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries)


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)


string[] splitInput = System.Text.RegularExpressions.Regex.Split(
                        InputString, "\r\n");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号