|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
File encodingHi everybody, I'm trying to create some text files in c#. I have not to
put the encoding preamble bytes at the beginning of the files, 'cause the unix software that reads my files gets some troubles with the preamble. How cna i do that?I know that using StreamWriter will alwais generate those bytes... Thanks Lorenzo <lorenzo.visca***@gmail.com> wrote:
> Hi everybody, I'm trying to create some text files in c#. I have not to No, it will only generate the preamble if you use an encoding which > put the encoding preamble bytes at the beginning of the files, 'cause > the unix software that reads my files gets some troubles with the > preamble. > How cna i do that?I know that using StreamWriter will alwais generate > those bytes... includes the preamble. If you don't specify the encoding, StreamWriter uses a UTF-8 encoding which doesn't include the preamble. If for whatever reason you need to specify the encoding, you can create a new instance of UTF8Encoding which doesn't include the preamble - just use new UTF8Encoding(false) -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too lorenzo.visca***@gmail.com wrote:
> Hi everybody, I'm trying to create some text files in c#. I have not If you want to use the existing framework code you can simply derive > to put the encoding preamble bytes at the beginning of the files, > 'cause the unix software that reads my files gets some troubles with > the preamble. > How cna i do that?I know that using StreamWriter will alwais generate > those bytes... > Thanks > Lorenzo from the class and override GetPreamble to return a zero length array (new byte[0]) Richard
Show quote
<"Richard Grimes [MVP]" <read my sig>> wrote: You don't need to do that though - both of the built-in encodings which > lorenzo.visca***@gmail.com wrote: > > Hi everybody, I'm trying to create some text files in c#. I have not > > to put the encoding preamble bytes at the beginning of the files, > > 'cause the unix software that reads my files gets some troubles with > > the preamble. > > How cna i do that?I know that using StreamWriter will alwais generate > > those bytes... > > Thanks > > Lorenzo > > If you want to use the existing framework code you can simply derive > from the class and override GetPreamble to return a zero length array > (new byte[0]) can generate preambles (Unicode and UTF-8) have constructors which let you tell the new instance not to generate a preamble. -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too Jon Skeet [C# MVP] wrote:
> You don't need to do that though - both of the built-in encodings Ahh, that is useful. Thanks for pointing it out.> which can generate preambles (Unicode and UTF-8) have constructors > which let you tell the new instance not to generate a preamble. Richard -- http://www.grimes.demon.co.uk/workshops/fusionWS.htm http://www.grimes.demon.co.uk/workshops/securityWS.htm |
|||||||||||||||||||||||