|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
to read a textfile regarding his formatA 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 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 > > 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 > > > > > > 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 <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) > 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. <arthurj***@gmail.com> schrieb:
>I copied and paste this char(é,à,è) in the notepad and Both will work if the file is stored using UTF-8. By specifying no encoding >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) 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/> 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/> > "andreas" <andr***@pandora.be> schrieb: AFAIK no.> 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? -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
updatecommand
int64 or double Design Question for Factory Pattern and Casting Types Floating Menu Bar Adding modules from another project Advice on Training Getting the Parent firectory of a file code convertor in VB.NET Express Edition remove xml node in xml document vb.net 2005 bug in the ide (wipes out code) |
|||||||||||||||||||||||