to read a textfile regarding his format

  • Thread starter Thread starter andreas
  • Start date Start date
A

andreas

A textfile can have different formats like ANSI,UTF8, Unicode ...
Using streamreader for a textfile can have different results for chars like
é,à,è....depending of the fileformat.
To solve this problem I have in the code analysed the chars in the beginning
of the textfile, named the BOM to see the system.text.encoding for using
this information in the streamreader.
But my question is :
Is there a way that vb.net can do this automatically?
Thanks for any response
 
with the boolean in the constructor of the streamreader you can set it to
automaticly detect the Byte Order Mark

regards

Michel Posseth
 
I have placed the code
dim sr as new streamreader(filename,true)
but the sr didn't recognise a ANSI file made with notepad
the chars é,à,è.... are disapeared
I missed something?
 
try this, maybe this will help.

Dim myStreamWriter As New StreamWriter(FileName, False,
System.Text.Encoding.Default)
 
I don't think that it helps because a system.text.encoding.default gives a
ANSI encoding and mentioning nothing gives UTF8
 
I copied and paste this char(é,à,è) in the notepad and
save it as UTF8 encoding.
then i tried the code below and i have no problem.
dim sr as new streamreader(filename,true)
and
Dim myStreamReader As New System.IO.StreamReader(objFile.FullName,
System.Text.Encoding.UTF8, False)

please check your textfile.
 
I copied and paste this char(é,à,è) in the notepad and
save it as UTF8 encoding.
then i tried the code below and i have no problem.
dim sr as new streamreader(filename,true)
and
Dim myStreamReader As New System.IO.StreamReader(objFile.FullName,
System.Text.Encoding.UTF8, False)


Both will work if the file is stored using UTF-8. By specifying no encoding
in the constructor, UTF-8 is used.
 
Thanks everyone but this is not what I want.
I know what is written.
I want to read the textfile without knowing what the format is
(ANSI,UTF8,Unicode...)
Now, I can do that only by code by looking at the first bytes in the file.
My question is , is there a method that the code read automaticly the right
format?
 
andreas said:
Thanks everyone but this is not what I want.
I know what is written.
I want to read the textfile without knowing what the format is
(ANSI,UTF8,Unicode...)
Now, I can do that only by code by looking at the first bytes in the file.
My question is , is there a method that the code read automaticly the
right
format?

AFAIK no.
 
Back
Top