Write to textfile in ANSI format

T

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
 
A

Armin Zingler

Thomas A said:
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

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top