I very rarely write to text files, but have encountered a situation where I cannot avoid it. I am using a StreamWriter to write lines of text to a text file. Here is a sample of what I have:
vb.net Code:
Dim WriteThisInfo As String = "12345678901234567890"
Using myStream As StreamWriter = New StreamWriter("Sample.txt")
my guess is that your PC's default language isn't English. right?
try using an encoding option:
Code:
Dim WriteThisInfo As String = "12345678901234567890"
Using myStream As New IO.StreamWriter("Sample.txt", False, System.Text.Encoding.Default)
myStream.WriteLine(WriteThisInfo)
End Using
my guess is that your PC's default language isn't English. right?
No, it's definitely English. I tried going down that path too, so I have tested using Encoding.Default and Encoding.ASCII but still got the same results. I don't see how this can happen when using different encoding types.
Show the love! Click (rate this post) under my name if I was helpful.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter
There's just no reason to use garbage like InputBox. - jmcilhinney
The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber
Just noticed something else that is weird. The default encoding is UTF-8. I have tried using Encoding.Default, which produced the results previously stated. However, if I use Encoding.UTF8, it actually displays in notepad correctly. Now if I could just figure out why it will not display ASCII.
Show the love! Click (rate this post) under my name if I was helpful.
Fun fact: If I open the file in Notepad as ANSI, instead of Unicode (my system defaults to Unicode) I get the correct text.
What in God's name .....I have to open it as UTF-8 for it to work correctly. Any other encoding produces garbage, even ANSI. This is really strange indeed.
[EDIT]
Wow, now it just took a turn into Twilight Zone strange....It opens correctly some of the time in NotePad using UTF-8. I really don't know where to start on figuring this out. Unicode is one strange beast indeed.
C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter
There's just no reason to use garbage like InputBox. - jmcilhinney
The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber