Vs reported "whether to standardize the end of a row because the end of a row is inconsistent in the following file"
Analysis:
By reading the source file, it is found that the line feed is "\ n"
Windows and Unix are caused by different standards... "Carriage Return" and "line feed...
| Symbol |
ASCII code |
Meaning |
| \ N |
10 |
Line feed NL |
| \ R |
13 |
Enter cr |
Before the computer appeared, there was a kind of device called teletype model 33, which can contain 10 characters per second. But there is a problem, that is, when a line breaks a line, it takes 0.2 seconds, just two characters. If a new character is passed in the 0.2 s, the character will be lost. As a result, the developers thought of a way to solve this problem, that is, adding two end characters after each line. One is "enter", which tells the typewriter to position the print head on the left boundary, and the other is "line feed", which tells the typewriter to move the paper down one line. In the GUI era, the cursor is moving freely without the significance of carriage return...
Therefore, Visual Studio, a text editor that meets the Windows development standards, will remind you that the currently edited text does not meet the Windows End-to-End standards ..
1. Line Break "\ r \ n" in Windows"
2. the Unix/Linux platform line break is "\ n ".
3. The line break of MessageBox. Show () is "\ n"
4. the console line break is "\ n"
Line breaks vary based on platform differences.
Solution:
1. To ensure the versatility of the platform, you can use the system default line break system. environment. newline.
2. replace all non-standard line breaks
1 class program_utf8 2 {3 static void main (string [] ARGs) 4 {5 string folderpath = @ "E: \ Folder path \"; 6 7 parsedirectory (folderpath ,"*. CS ", (filepath) => 8 {9 string text =" "; 10 using (streamreader READ = new streamreader (filepath, encoding. default) 11 {12 string oldtext = read. readtoend (); 13 text = oldtext; 14 text = text. replace ("\ n", "\ r \ n"); 15 text = text. replace ("\ r \ n", "\ r \ n"); // prevents replacement of normal line breaks If (oldtext. length = text. length) 17 {18 console. writeline (filepath. substring (filepath. lastindexof ("\") + 1) + "do not require standardization"); 19 return; // exit 20} 21} 22 file if no change occurs. writealltext (filepath, text, encoding. utf8); // saves the UTF-8 format to prevent garbled 23 24 console. writeline (filepath. substring (filepath. lastindexof ("\") + 1) + "end-to-end standardization completed"); 25}); 26 27 console. readkey (); 28} 29 30 // <summary> recursively retrieve all directories, locate the files based on the filter, and use the delegate for unified processing </Summary> 31 // <Param name = "info"> </param> 32 // <Param name = "filter"> </param> 33 // <param name = "action"> </param> 34 static void parsedirectory (string folderpath, string filter, Action <string> action) 35 {36 IF (string. isnullorwhitespace (folderpath) 37 | folderpath. endswith ("debug", stringcomparison. ordinalignorecase) 38 | folderpath. endswith ("OBJ", stringcomparison. ordinalignorecase) 39 | folderp Ath. endswith ("bin", stringcomparison. ordinalignorecase) 40 return; 41 42 console. writeline ("read Directory:" + folderpath); 43 44 // process file 45 string [] filenamearray = directory. getfiles (folderpath, filter); 46 If (filenamearray. length> 0) 47 {48 foreach (VAR filepath in filenamearray) 49 {50 action (filepath); 51} 52} 53 else54 {55 console. writeline ("no file found! "); 56} 57 58 console. writeline ("========================================" ); 59 60 // obtain the subdirectory and recursively process 61 string [] dirs = directory. getdirectories (folderpath); 62 var iter = dirs. getenumerator (); 63 while (ITER. movenext () 64 {65 string STR = (string) (ITER. current); 66 parsedirectory (STR, filter, action); 67} 68} 69}View code
Vs reported "whether to standardize the end of a row because the end of a row is inconsistent in the following file"