Reading text files and accentuated characters

J

jcdperf

Hello,

I have small problems while reading of text files containing
accentuated characters. (like é è à ç ...). I use this basic code :


Dim sr As StreamReader
Try
sr = New StreamReader(sFichier)
Dim sLine As String
Do
sLine = sr.ReadLine()
Console.WriteLine(sLine
Loop Until sLine Is Nothing

Catch e As Exception
Console.WriteLine(e.Message)
Finally
sr.Close()
End Try


When sLine is printed in the console (or when i have to manipulate
this string), all the accentuated characters have disappeared from
sLine. For example,
"Début de programme" is replaced by "Dbut de programme".

I have tried also FileStream with UTF8Encoding to read the text file,
but with no more success.

Any help is welcome.

Thanks,

Cedric

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
G

Guest

Hello,

a similar question appeared in the Spanish dotnet.vb newsgroup.

Use Encoding with 437 code (OEM US):

sr = New StreamReader(sFichier, System.Text.Encoding.GetEncoding(437), False)

Try it and give me your feedback please. ;-)


Kind Regards,

Jorge Serrano
MVP VB.NET
 
J

jcdperf

Hello Jorge,

thanks for your help, you put me on the right way. i have used


sr = New StreamReader(sFichier, Encoding.Default)


It seems to use the default encoding of the system in order to read
the text file. It works well for me. You have to use this for the
StreamWriter too if you want to write accentuated characters.

[code:1:a7847f6618]System.Text.Encoding.GetEncoding(437)[/code:1:a7847f6618]
doesn't work on my system, certainly because it's not a spanish sytem
but a french one :D

Regards,

Cedric

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top