364,111 Members | 2134 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Write to textfile in ANSI format

Thomas A
P: n/a
Thomas A
Hi,

I write a string value to a textfile , if the string dont contains swedish
Å,Ä and Ö , the file will be written in ANSI.

So far so god but....

If the string contains Å or Ä or Ö ,the file will be written in UTF-8.

Thats not good, have anyone a tips for me so it always will be written in
ANSI.

My code is now:

'The Outstring contains my string to write into my file

Dim OutPath as string = "c:\test.txt"
Dim mySW As StreamWriter

mySW = File.CreateText(OutPath)

' Debug.Write(mySW.Encoding)
mySW.Write(Outstring)
mySW.Close()
mySW.Flush()


//Thomas
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


Armin Zingler
P: n/a
Armin Zingler
"Thomas A" <thomasalbertsson@msn.com> schrieb[color=blue]
> Hi,
>
> I write a string value to a textfile , if the string dont contains
> swedish Å,Ä and Ö , the file will be written in ANSI.
>
> So far so god but....
>
> If the string contains Å or Ä or Ö ,the file will be written in
> UTF-8.
>
> Thats not good, have anyone a tips for me so it always will be
> written in ANSI.
>
> My code is now:
>
> 'The Outstring contains my string to write into my file
>
> Dim OutPath as string = "c:\test.txt"
> Dim mySW As StreamWriter
>
> mySW = File.CreateText(OutPath)
>
> ' Debug.Write(mySW.Encoding)
> mySW.Write(Outstring)
> mySW.Close()
> mySW.Flush()
>
>
> //Thomas[/color]

dim fs as filestream
fs = new filestream(outpath, ...)

mysw = new streamwriter(fs, System.Text.Encoding.Default)


--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2

Thomas A
P: n/a
Thomas A
"Armin Zingler" <az.nospam@freenet.de> wrote in news:eIzTGWVzDHA.2928
@TK2MSFTNGP09.phx.gbl:
[color=blue]
> "Thomas A" <thomasalbertsson@msn.com> schrieb[color=green]
>> Hi,
>>
>> I write a string value to a textfile , if the string dont contains
>> swedish Å,Ä and Ö , the file will be written in ANSI.
>>
>> So far so god but....
>>
>> If the string contains Å or Ä or Ö ,the file will be written in
>> UTF-8.
>>
>> Thats not good, have anyone a tips for me so it always will be
>> written in ANSI.
>>
>> My code is now:
>>
>> 'The Outstring contains my string to write into my file
>>
>> Dim OutPath as string = "c:\test.txt"
>> Dim mySW As StreamWriter
>>
>> mySW = File.CreateText(OutPath)
>>
>> ' Debug.Write(mySW.Encoding)
>> mySW.Write(Outstring)
>> mySW.Close()
>> mySW.Flush()
>>
>>
>> //Thomas[/color]
>
> dim fs as filestream
> fs = new filestream(outpath, ...)
>
> mysw = new streamwriter(fs, System.Text.Encoding.Default)
>
>[/color]

Excellent !

Thank you

//Thomas
Nov 20 '05 #3

Post your reply

Help answer this question



Didn't find the answer to your Visual Basic .NET question?

You can also browse similar questions: Visual Basic .NET