当我执行这段代码时,我得到了一些有趣的结果。
string readText = File.ReadAllText("d:\\temp.txt");
Console.WriteLine(readText);
Console.WriteLine("From File: "+Regex.Matches(readText,"$").Count);//-->2
Console.WriteLine("Add \\n to the File: "+Regex.Matches(readText + "\n", "$").Count);//--->2
Console.WriteLine("Add multiple \\n to the file: "+Regex.Matches(readText + "\n\n\n", "$").Count);//--->2
Console.WriteLine("on Text \"sample\": "+Regex.Matches("sample", "$").Count);//--->1
Console.WriteLine("on Text \"sample\\n\\n\\n\": "+Regex.Matches("sample" + "\n\n\n", "$").Count);//--->2
输出:
First line
third
Line 6
Line 7
From File: 2
Add \n to the File: 2
Add multiple \n to the file: 2
on Text "sample": 1
on Text "sample\n\n\n": 2
为什么它给我这样的结果。任何一个前飞机都可以吗?