accents removed when reading from text file
i am reading a text file line by line like this
VB Code:
dim reader As StreamReader = New StreamReader("c:\myfile.txt")
Do While Not reader.EndOfStream
msbox reader.readline
loop
the accents characters are removed..
e.g.
instead of displaying
"González"
it displays
"Gonzlez"
any idea why??
Re: accents removed when reading from text file
It has got to do with the encoding when reading in text. You have to specify the encoding type. Like this:
VB Code:
Dim myString() As String = System.IO.File.ReadAllLines("C:\Temp\Try1.txt", System.Text.Encoding.UTF7)
For i As Integer = 0 To myString.Length - 1
MessageBox.Show(myString(i))
Next
Re: accents removed when reading from text file
ok thx.. i used to use filesystemobject in vb6 and tried it on vb 2005 too and it's working fine.....
Re: accents removed when reading from text file
By default, the system.io classes (I like to call them 'tools') use Unicode as encoding when reading. When saving they normally use the same encoding that has been used for reading or the encoding that was last used internally on a string.
If your app will be used on computers with different regional settings, the least complicated approach is to resave all external chunks of text (.txt, .doc, .xls etc) in unicode. This way, even chinese text opened in Notepad on a polish PC will keep its symbols. Same goes for VB programs.
I once thought that the whole encoding stuff is a total chaos but after reading this great tutorial I at least understand the chaos :)
Unfortunately, XP and possibly all other OSes in the family are not Unicode enabled, so without some third party external patching you will have missing accents and other formatting in messageboxes, file names and so on IF the computer is not set up with the respective regional settings.
Re: accents removed when reading from text file
the unicode stuff... etc..i dun understand it very well.... :( ... i am always confused with it...
Re: accents removed when reading from text file
As I said, the differences are explained very well here:
http://www.joelonsoftware.com/articles/Unicode.html
You will hardly ever have a problem after reading it.
Re: accents removed when reading from text file
Ok thanks will try to find a courage to read it :) ty