Article ID: 889835 - View products that this article applies to.
When you use the StreamReader.ReadLine method to try to read a text file that contains extended characters, the extended characters are removed from the line that is being read.
Note An example of an extended character is a character with an accent, such as the é, ò, or à characters.
This problem occurs when the text file is not saved by using Unicode Translation Format (UTF) encoding. By default, the StreamReader class uses UTF encoding. Therefore, when the ReadLine method reads the text-file line, the extended characters are not correctly read.
To work around this problem, you must specify the correct UTF encoding by using the StreamReader class, or you must save the text file by using UTF encoding.
The following example shows how to read a text file by using UTF encoding. This example uses the encoding System.Text.Encoding.Default property that corresponds to the system's current ANSI code page.
Visual Basic .NET or Visual Basic 2005
Note In Visual Studio 2005, by default, Program.cs is created.
Note When you pass the System.Text.Encoding.Default property as the second parameter of the StreamReader method, the system's current ANSI code page is used to decode the file.
For more information about the StreamReader class, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/system.io.streamreader(vs.71).aspxFor more information about the Encoding class, visit the following Microsoft Developer Network (MSDN) Web site:
Article ID: 889835 - Last Review: May 18, 2007 - Revision: 2.3
Contact us for more help
Connect with Answer Desk for expert help.