Extended ASCII in C#

Posted on 2011-10-19
Medium Priority
Last Modified: 2012-05-12
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

Question by:ASPDEV
  • 2
LVL 84

Expert Comment

by:Dave Baldwin
ID: 36997323
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".

Expert Comment

ID: 36998724

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

That should do the trick.

Accepted Solution

phill_cahill earned 2000 total points
ID: 36998767
Try this also.

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


Author Closing Comment

ID: 37000718

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question