Missing special symbols
-
Hello, I was trying to get the content of a file in a string. I have used the following code ...
String strContent = ""; FileStream flDoc = new FileStream(m\_tbxBrowser.Text, FileMode.Open, FileAccess.Read); Byte\[\] bytContent = new Byte\[flDoc.Length\]; flDoc.Read(bytContent, 0, Convert.ToInt32(flDoc.Length)); strContent = System.Text.ASCIIEncoding.ASCII.GetString(bytContent);
But in the output, strContect some special symbols like
®
is missing, and is replaced by
???
Can anyone help me to solve this? Thanks in advance.
Sebastian
-
Hello, I was trying to get the content of a file in a string. I have used the following code ...
String strContent = ""; FileStream flDoc = new FileStream(m\_tbxBrowser.Text, FileMode.Open, FileAccess.Read); Byte\[\] bytContent = new Byte\[flDoc.Length\]; flDoc.Read(bytContent, 0, Convert.ToInt32(flDoc.Length)); strContent = System.Text.ASCIIEncoding.ASCII.GetString(bytContent);
But in the output, strContect some special symbols like
®
is missing, and is replaced by
???
Can anyone help me to solve this? Thanks in advance.
Sebastian
The ASCII encoder substitutes a ? when it encounters a character code above 127. What you probably have in the file is an extended ascii character set, the most common of which is represented in Windows by the code page 1252, Single Byte Character Sets (SBCS)[^]. You can get an instance of the encoding with
Encoding coder = Encoding.GetEncoding(1252);
If you are going to write to the file I strongly suggest that you do some round trip tests to check that you have selected the correct encoding. i.e. Read the file Convert to a string using the encoding Convert the string back to bytes Write to a new file Check that the orignal and rewritten file are identical Alan.