I am having some issues with the default string encoding in C#. I need to read strings from certain files/packets. However, these strings include characters from the 128-256 range (extended ascii), and all of these characters show up as question marks , instead of the proper character. For example, when reading a string ,it could come up as “S?meStr?n?” if the string contained the extended ascii characters.
Now, is there any way to change the default encoding for my application? I know in java you could define the default character set from command line.
There’s no one single “extended ASCII” encoding. There are lots of different 8-bit encodings which are compatible with ASCII for the bottom 128 values.
You need to find out what encoding your files actually use, and specific that when reading the data with
StreamReader(or whatever else you’re using). For example, you may want encoding Windows-1252:.NET strings are always sequences of UTF-16 code points. You can’t change that, and you shouldn’t try. (That’s true in Java as well, and you really shouldn’t use the platform default encoding when calling
getBytes()etc unless that’s what you really, really mean.)