Extended ASCII in C#

Hello Experts,

I have a string with extended characters in it.

string   str = "›¥›";

When I convert into Byte, it's  byte value is different:
System.Text.Encoding ascii = System.Text.Encoding.ASCII;
                            Byte[] encodedBytes = ascii.GetBytes(str );

All the extended characters are converted into  ?(Question Mark), instead of their original extended characters.

Result:: ???
encodeBytes[0]   char is ' ?' and value is 63. // Instead '>' and value 155
encodeBytes[1]   char is  '?' and value is 63. // Instead '¥' and value 165
encodeBytes[2]   char is  '?' and value is 63. // Instead '>' and value 155


Thanks,
ASPDEV
ASPDEVAsked:
Who is Participating?
 
phill_cahillConnect With a Mentor Commented:
Try this also.

System.Text.Encoding ascii = System.Text.Encoding.Default;

0
 
Dave BaldwinFixer of ProblemsCommented:
ASCII is defined as the lowest 7-bit character set.  It doesn't have any characters with a value greater than 127.  "Extended ASCII" is as term kind of leftover from DOS days.  Now we have "Character sets".  My best reference for that is http://www.alanwood.net/ .  Here is the Microsoft page http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx for "System.Text.Encoding".
0
 
phill_cahillCommented:
Try

System.Text.Encoding ascii = System.Text.Encoding.Unicode;

That should do the trick.
0
 
ASPDEVAuthor Commented:
Worked!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.