如何一行行读string

来源:百度知道 编辑:UC知道 时间:2024/05/31 15:11:42
已经有若干行内容的string类message,要怎么从message中把内容一行行的读出

两种方法:
方法1:
string s1 = "11\r\n22";
string[] s2 = s1.Split(new string[] { "\r\n" }, StringSplitOptions.None);

方法2:
string s1 = "11\r\n22";
System.IO.StringReader sr = new System.IO.StringReader(s1);
string s2 = string.Empty;
while ((s2 = sr.ReadLine()) != null)
{
// 对s2操作
}