Detect Carriage return in a string
本问题已经有最佳答案,请猛点这里访问。
我有以下问题:
1 2 3 4 | String line = @"Line1 Line2 Line3 Line4"; |
我试图创建一个循环,用于检测何时遇到回车符,并将每行存储在单独的字符串中。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | String value static long LinesCount(string s) { long count = 0; int position = 0; while ((position = s.IndexOf(' ', position)) != -1) { count++; } return count; } for (int i = 1; i > LinesCount(line); i++) { value = line.Split(Environment.NewLine) } |
号
trying to create a loop that detects when the carriage return character is encountered and store each row on a separate string.
号
用
'
1 2 3 4 5 6 7 8 9 10 11 | String line = @"Line1 Line2 Line3 Line4"; string[] lines = line.Split(' '); foreach(var L in lines) { Console.Write(L); Console.WriteLine(';'); // for demonstration purpose } |
控制台输出
1 2 3 4 | Line1; Line2; Line3; Line4; |
号
演示