问题描述:

I have a .txt file with the text split up in a number of lines. However, after I loop with C# all the characters via the following code

public static void printChars(string text)

{

char[] myChars = text.ToCharArray();

foreach (char ch in myChars)

{

System.Console.Write(ch + @" - \u" + ((int)ch).ToString("X4") + ", ");

}

System.Console.WriteLine();

}

The issue is that I cannot see any new line characters (for example, u000A) or something since there are much text starting in new lines (for example u000D). How to detect that kind of unicode characters?

网友答案:

The most obvious explanation is that you wrote your code correctly and use StreamReader to read the text file. Its ReadLine() method returns a line of text from the file without the line terminator. Fairly important that it works that way, line terminators are not well standardized.

Not the only way it transforms the content of the file, its Encoding is important as well. Another detail that is not well standardized, still lots of text files around that don't use utf-8.

If you want to see the raw bytes in the file then you must use FileStream. And byte[] instead of string.

相关阅读:
Top