Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > Unreadeble text
 

Unreadeble text

Hey,
I have a question about strings.
I have the following string in my program:

Dim test as String = ")eõÜg;aa2ã"

Then I save it to an simple txt file.

my.computer.filesystem.writealltext("C:\test.txt", test)

Till her everything goes fine. But when I try to reopen that txt file it doesn't give me the right string.
If I use following code:

test = my.computer.filesystem.readalltext("C:\test.txt")

Then I get this string: ")e??g;aa2?"
' The question marks are actualy some little rectangles, but I couldn't paste this in here :(

Does Anyone know why some characters of my string are changed after saving?

many thanks in progress

Dhondtie

There are 10 types of people in this world; those who understand binary and those who don't.
  • Changed TypeRiquel_DongModeratorFriday, June 20, 2008 2:39 AMdon't follow up with the necessary information
  •  
Dhondtie  Sunday, June 15, 2008 9:36 AM
I cannot reproduce your problem. But you have a problem with text encoding. This has something to do with the version of Visual Studio you use and the country you live in. VS2008 saves source code with the UTF8 encoding. VS2005 saves it using the local code page. Not sure about versions before that, I'd guess at local code page. WriteAllText and ReadAllText write and read using the UTF8 encoding.

Key questions are: where do you live and what version do you use?

Hans Passant.
nobugz  Sunday, June 15, 2008 8:37 PM
I live in Belgium
and uses VB2005 and VB2008. Just tell me, wich one is best please

There are 10 types of people in this world; those who understand binary and those who don't.
Dhondtie  Monday, June 16, 2008 7:15 PM
Hmya, nothing that unusual about your location. Unless the Walloons are messing with you. VS2008 does a better job of encoding your source code files since it doesn't rely on the default code page. Not sure if that's the answer you needed.
Hans Passant.
nobugz  Monday, June 16, 2008 10:52 PM
Hi Dhondtie,

Or you can explicitly set Encoding in this scenario. Have a look at the following method.

PublicSubWriteAllText(_
ByValfileAsString,_
ByValtextAsString,_
ByValappendAsBoolean,_
ByValencodingAsSystem.Text.Encoding_
)


Best regards,
Riquel

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Riquel_Dong  Wednesday, June 18, 2008 11:34 AM

You can use google to search for other answers

Custom Search

More Threads

• OpenFileDialog and streamreader
• Highlight the Row in listview control
• How to trim non-alphanumeric characters from a string
• Zoom in and out
• From VB6 to VB2005
• Help needed to create a 'generic' conversion function please. To2dArray
• Combobox Arrays and listboxes :-(
• Difference between And and AndAlso???
• Datagrid Row Question
• Compare objects