Home All Groups Group Topic Archive Search About

to read a textfile regarding his format

Author
13 May 2006 4:39 PM
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

Author
14 May 2006 6:49 AM
Michel Posseth [MCP]
with the boolean in the constructor of the streamreader you can set it to
automaticly detect the Byte Order Mark

regards

Michel Posseth



Show quoteHide quote
"andreas" <andr***@pandora.be> schreef in bericht
news:6Zn9g.422959$PO.11297938@phobos.telenet-ops.be...
>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
>
>
Author
14 May 2006 11:03 AM
andreas
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?


Show quoteHide quote
"Michel Posseth [MCP]" <M***@posseth.com> wrote in message
news:#vixJKydGHA.1436@TK2MSFTNGP05.phx.gbl...
> with the boolean in the constructor of the streamreader you can set it to
> automaticly detect the Byte Order Mark
>
> regards
>
> Michel Posseth
>
>
>
> "andreas" <andr***@pandora.be> schreef in bericht
> news:6Zn9g.422959$PO.11297938@phobos.telenet-ops.be...
> >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
> >
> >
>
>
Author
15 May 2006 1:25 AM
arthurjr07
try this, maybe this will help.

Dim myStreamWriter As New StreamWriter(FileName, False,
System.Text.Encoding.Default)
Author
15 May 2006 5:49 AM
andreas
I don't think that it helps because a system.text.encoding.default gives a
ANSI encoding and mentioning nothing gives UTF8

<arthurj***@gmail.com> wrote in message
Show quoteHide quote
news:1147656334.913759.12200@v46g2000cwv.googlegroups.com...
> try this, maybe this will help.
>
> Dim myStreamWriter As New StreamWriter(FileName, False,
> System.Text.Encoding.Default)
>
Author
15 May 2006 7:27 AM
arthurjr07
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.
Author
15 May 2006 8:35 AM
Herfried K. Wagner [MVP]
<arthurj***@gmail.com> schrieb:
>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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
15 May 2006 3:29 PM
andreas
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?


Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:#BhGPq$dGHA.1792@TK2MSFTNGP03.phx.gbl...
> <arthurj***@gmail.com> schrieb:
> >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.
>
> --
>  M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
>  V B   <URL:http://classicvb.org/petition/>
>
Author
15 May 2006 4:24 PM
Herfried K. Wagner [MVP]
"andreas" <andr***@pandora.be> schrieb:
> 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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>