Problem with read file

  • Thread starter Thread starter Saep
  • Start date Start date
S

Saep

Hi,
I have a problem with Compact Framework VB.Net.
I open a textfile with:

Dim sr As StreamReader
sr = File.OpenText(ParametriApplicativi.PercorsoPCFTP & "\phvrx.txt")

Then I read the line with:
strRiga = sr.Read()

The line in my Text file is 200 Characters. If in this line there is a
character '£', this character is omitted and my line in strRiga is
lenght 199 character!
Why??
 
That's because you forgot to set up correct encoding.
There's an overload of StreamReader constructor which allows you to set
encoding you need.
In that case it would be encoding this text file is in. Or, change this file
to use default encoding which is UTF8.
That might be your only option as not all encodings are supported on device.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Ilya,
thnks for your reply.
But I don't understand a thing...
How do I set up the correct encoding?
Can you give me an example?

Thanks
Marco Figini


Ilya Tumanov said:
That's because you forgot to set up correct encoding.
There's an overload of StreamReader constructor which allows you to set
encoding you need.
In that case it would be encoding this text file is in. Or, change this file
to use default encoding which is UTF8.
That might be your only option as not all encodings are supported on device.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
 
You need to do something like this:

sr = New StreamReader(New FileStream(ParametriApplicativi.PercorsoPCFTP &
"\phvrx.txt", FileMode.Open),
Encoding.GetEncoding(CODE_PAGE_YOUR_FILE_IS_IN))

If you do not understand what encoding/codepage is, please read this:

http://www.joelonsoftware.com/articles/Unicode.html

And after that, this:

http://www.yoda.arachsys.com/csharp/unicode.html

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.


Hi Ilya,
thnks for your reply.
But I don't understand a thing...
How do I set up the correct encoding?
Can you give me an example?

Thanks
Marco Figini
 
Back
Top