reading from file with special characters

martins87

Member
Joined
Jul 29, 2006
Messages
10
Programming Experience
Beginner
Im building an application in my local language (that would be latvian). All special characters are displayed corectly but not when reading txt file into Rich text box... (if win system language is latvian, everything is alright, but it is really uncomfortable to use unpopular system language). is there any way to read from file with all special characters displayed correctly?
 
When you create a Streamreader or StreamWriter you can specify an Encoding to use. For many languages it would be necessary to use Unicode or something else so that non-ASCII characters are interpreted correctly.
 
E.g.
VB.NET:
'Use the default encoding.
Using sr As New IO.StreamReader("file path here")
    MessageBox.Show(sr.ReadToEnd())
End Using

'Use the default encoding unless a recognised encoding is detected.
Using sr As New IO.StreamReader("file path here", True)
    MessageBox.Show(sr.ReadToEnd())
End Using

'Use a specific encoding.
Using sr As New IO.StreamReader("file path here", System.Text.Encoding.Unicode)
    MessageBox.Show(sr.ReadToEnd())
End Using

'Use a specific encoding unless a recognised encoding is detected.
Using sr As New IO.StreamReader("file path here", System.Text.Encoding.Unicode, True)
    MessageBox.Show(sr.ReadToEnd())
End Using
 
Back
Top