simple conversion string->bytes->string changes my data???

  • Thread starter Thread starter Jazper
  • Start date Start date
J

Jazper

hi

can anybody explain that to me:
i did the following:
- 1. input of char 244 ("ô") into string
- 2. convert to getbytes
- 3. convert back to string

char 244 changed to char 63 ("?")
why??? what can i do the get the same string...?

--- Code -------------------------------
string str = ((char)244).ToString(); //"ô"
byte[] btVal = System.Text.ASCIIEncoding.ASCII.GetBytes(str);
string str2 = System.Text.ASCIIEncoding.ASCII.GetString(btVal);
--- Code -------------------------------

regards, jazper
 
plz dont let me beg and weep...
how can i solve my problem. (i dont want to read a book about utf-8 to solve
this little problem) :-)

so, where can i set the encoding type for GetBytes() and GetString()?

pleeeeease...
Jazper.
 
Try one of the static Encoding methods:

string str=((char)244).ToString();
byte[] bytes=Encoding.UTF8.GetBytes(str);
string str2=Encoding.UTF8.GetString(bytes);

Austin Ehlers

plz dont let me beg and weep...
how can i solve my problem. (i dont want to read a book about utf-8 to solve
this little problem) :-)

so, where can i set the encoding type for GetBytes() and GetString()?

pleeeeease...
Jazper.
 
cool, thank you for your short solution, austin.
works fine!
cheers, jazper


Austin Ehlers said:
Try one of the static Encoding methods:

string str=((char)244).ToString();
byte[] bytes=Encoding.UTF8.GetBytes(str);
string str2=Encoding.UTF8.GetString(bytes);

Austin Ehlers
 
cool, thank you for your short solution, austin.
works fine!
cheers, jazper


Austin Ehlers said:
Try one of the static Encoding methods:

string str=((char)244).ToString();
byte[] bytes=Encoding.UTF8.GetBytes(str);
string str2=Encoding.UTF8.GetString(bytes);

Austin Ehlers
 
Back
Top