StreamWriter problem

F

fniles

I am using VB.NET 2005 and streamWriter to write to a file.
Before writing to the file, I encrypt the string.
StreamWriter does not write it correctly to the file, I have to change to
FileOpen, Print and FileClose to write it correctly to a file.
StreamWriter will write something like:
ÃzÃ,Ãz¬±°±¸²¬Ã,±°°²¬ÃSáòöéóüÂ
instead of
ÞÂÞ¬±°±¸²¬Â±°°²¬Êáòöéóü

Why does StreamWriter write it incorrectly ? Can I write those ascii
characters using StreamWriter ?
Thank you.

Dim swFile As StreamWriter

Crypt(Account1)
swFile = New streamWriter("c:\test.HTM", False)
swFile.Write(re)
swFile.Close()

Public Function Crypt(ByVal Text As String) As String
Dim strTempChar As String
Dim I As Int16

For I = 1 To Len(Text)
strTempChar = Asc(Mid$(Text, I, 1)) + {some number}
Mid$(Text, I, 1) = Chr(strTempChar)
Next I
Crypt = Text
 
H

Herfried K. Wagner [MVP]

fniles said:
I am using VB.NET 2005 and streamWriter to write to a file.
Before writing to the file, I encrypt the string.
StreamWriter does not write it correctly to the file, I have to change to
FileOpen, Print and FileClose to write it correctly to a file.
StreamWriter will write something like:
ÃzÃ,Ãz¬±°±¸²¬Ã,±°°²¬ÃSáòöéóüÂ
instead of
ÞÂÞ¬±°±¸²¬Â±°°²¬Êáòöéóü

Why does StreamWriter write it incorrectly ? Can I write those ascii
characters using StreamWriter ?

'StreamWriter' uses the UTF-8 encoding by default. Maybe the application
you are using to view the file assumes or expects another encoding. The
'StreamWriter' class' constructor is overloaded---one overload expects a
'System.Text.Encoding' object.
 
H

Harry

Herfried K. Wagner said:
'StreamWriter' uses the UTF-8 encoding by default. Maybe the application
you are using to view the file assumes or expects another encoding. The
'StreamWriter' class' constructor is overloaded---one overload expects a
'System.Text.Encoding' object.
You are the man, Herfried! Just another reason why VB 2005 is so cool... The
language requires considerable study. I have found that I was not able to
beat it into the VB6 shape (grin). Consequently, my coding has improved
hugely.

Herfried, while on the subject of VS 2005, what are your observations of VS
2008?
 
H

Herfried K. Wagner [MVP]

Harry said:
Herfried, while on the subject of VS 2005, what are your observations of
VS 2008?

Unfortunately I didn't yet have the opportunity to work with VS 2008 :-/.
 

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