writing the degree symbol to a text file

Hi,

I'm tring to write a string to a plain text file. The string contains ASCII code 176, the degree symbol. In the text file it is written as ° (capital A circumflex accent and then the degree symbol).

How can I just write the degree symbol? I suspect it has something to do with character sets?

TIA,
JosP
JosPAsked:
Who is Participating?
 
VBRocksConnect With a Mentor Commented:
Here's the same thing, with it used in a sentence.  View it in Notepad, and you'll see it worked correctly.

        Dim str As String = "The temperature in Albuquerue, NM is about 90" & Chr(176) & " today."

        Dim path As String = "c:\temp\test.out"

        Dim sw As New StreamWriter(path, False, System.Text.Encoding.Unicode)
        sw.WriteLine(str)
        sw.Close()

        MsgBox("Done")

0
 
athapaCEO / CTOCommented:
If you are using StreamWriter then you can specify encoding. Something like "iso-8859-1" should work for usual plain text.
0
 
VBRocksCommented:
You can write it out specifying Unicode encoding.  Here's an example:

        Dim character As Char = Chr(176)

        Dim path As String = "c:\temp\test.out"

        Dim sw As New StreamWriter(path, False, System.Text.Encoding.Unicode)
        sw.WriteLine(character)
        sw.Close()

        MsgBox("Done")

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.