Can't get this code to display £ chars
I have a simple text file created with notepad and I am trying to load it into a textbox with this code:
VB Code:
If ofd.ShowDialog = DialogResult.OK Then
If File.Exists(ofd.FileName) Then
Dim sr As StreamReader = New StreamReader(ofd.FileName)
Try
txtOriginal.Text = sr.ReadToEnd
Catch ex As Exception
MessageBox.Show("Could not load that file: " & ex.Message, "Censor", MessageBoxButtons.OK)
Finally
'tidy up a bit
txtOriginal.SelectionLength = 0
sr.Close()
End Try
End If
End If
My file has some "£" (British Pounds Sterling symbol, (Shift + 3) on most keyboards.
The whole file loads ok except for the sterling signs. What gives? If I go out of my way to make it work, save the file in unicode, and try again it works OK, but not all of my files will be in unicode).
I'm pretty sure it should show EVERY single printable char in the file (regardless of its encoding), in the textbox, yet this is not the case.
Re: Can't get this code to display £ chars
I have tried to open several files in this way. The text for some characters is non-displayable, and the ASC code for them all is 63 ("?") though the characters are not question marks and are not the same character.
It is causing me a problem because these characters in the file are part of the delimiter that separates data. I cannot split the text over the delimiter because VB.Net doesn't compare it correctly, whether I use the Mid() to compare a portion of the text string itself, or type in chr(63) for these characters as the splitter. It won't work.
Any thoughts?
Re: Can't get this code to display £ chars
also, if I paste the delimiter string into the VB code myself, and save, I'll get an error message that some chars won't be saved, then the chars in question will become little boxes in the source code. But then when I run the app, it splits the text correctly!
Problem is each file has a unique delimiter, located at the same position in the file (to define it) and I have to be able to get that code into the text and have it compare correctly in order to split the data over it.