StreamReader and accentuated characters

  • Thread starter Thread starter Marcos Ribeiro
  • Start date Start date
M

Marcos Ribeiro

Hi
I'm trying to read a textfile using System.IO.StreamReader, but all
accentuated characters are skiped.
Why's that? There is any workaround?
Thanks
Marcos
 
Marcos,
You have the incorrect encoding set on the StreamReader.

When you create the StreamReader use the constructor that accepts a
System.Text.Encoding object, then pass an Encoding object that is the
correct format (code page) for your file.

You can use one of the predefined encodings such as
System.Text.Encoding.UTF8, or you can use Encoding.GetEncoding to get a
specific code page.

Hope this helps
Jay
 
Here it is:

Dim sBigString As String
Dim sr As System.IO.StreamReader
sr = System.IO.File.OpenText("MyArq.html")
While sr.Peek <> -1
sBigString &= sr.ReadLine()
End While
sr.Close()

If MyArq.html contain characters like çâé they are zapped from the string
So my Middle Name "Masagão" becomes "Masago"

Marcos
 
Hello,

Marcos Ribeiro said:
I'm trying to read a textfile using System.IO.StreamReader, but all
accentuated characters are skiped.
Why's that? There is any workaround?

You read the file with the wrong encoding. You can specify an encoding in
the StreamReader's constructor.

HTH,
Herfried K. Wagner
 
Its OK now
Im using
Dim sr As System.IO.StreamReader = New System.IO.StreamReader("Myfile",
System.Text.Encoding.GetEncoding(1252))
While sr.Peek <> -1
sRet &= sr.ReadLine()
End While
sr.Close()
sr = Nothing

Thanks to all
 
Back
Top