|
-
Jan 15th, 2007, 06:52 AM
#1
Thread Starter
Addicted Member
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??
-
Jan 15th, 2007, 07:50 AM
#2
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
-
Jan 15th, 2007, 09:56 AM
#3
Thread Starter
Addicted Member
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.....
-
Jan 15th, 2007, 10:51 AM
#4
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.
-
Jan 15th, 2007, 12:22 PM
#5
Thread Starter
Addicted Member
Re: accents removed when reading from text file
the unicode stuff... etc..i dun understand it very well.... ... i am always confused with it...
-
Jan 15th, 2007, 12:31 PM
#6
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.
-
Jan 15th, 2007, 02:20 PM
#7
Thread Starter
Addicted Member
Re: accents removed when reading from text file
Ok thanks will try to find a courage to read it ty
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|