Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2007

Tip: Looking for answers? Try searching our database.

UCS and BMP Character Sets

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeffrey Walton - 20 Nov 2007 18:44 GMT
HI All,

I' working on an ASN.1 parser. The Content Octets (data values) are
stored in a byte[]. The conversion of byte[] to char[] is fairly
trivial. BMP is a special case of UCS, using the lower 65 thousand
characters. Reference http://en.wikipedia.org/wiki/Universal_Character_Set#Encoding_forms_of_the_Unive
rsal_Character_Set


How do I specify a character set of UCS (ISO/IEC 10646) when invoking
a string constructor?

Thanks,
Jeff
Jeffrey Walton
Jon Skeet [C# MVP] - 20 Nov 2007 19:21 GMT
> I' working on an ASN.1 parser. The Content Octets (data values) are
> stored in a byte[]. The conversion of byte[] to char[] is fairly
> trivial. BMP is a special case of UCS, using the lower 65 thousand
> characters.

<snip>

> How do I specify a character set of UCS (ISO/IEC 10646) when invoking
> a string constructor?

You don't build a string from bytes, you build it from Unicode
characters (or UTF-16 code points really).

You want to use System.Text.Encoding.GetString(byte[]) to convert from
bytes to a string.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Jeffrey Walton - 20 Nov 2007 20:04 GMT
Hi John,

Thanks for the quick reply.

> You don't build a string from bytes, you build it from Unicode
> characters (or UTF-16 code points really).
I know I am off slightly with respect to the paradigm.

> You want to use System.Text.Encoding.GetString(byte[]) to convert from
> bytes to a string.
Thank you very much. I was cruising your site earlier. The example
presented is based on a Stream (but I have a byte array). I was hoping
for a more applicable answer.

I also saw a T.61 string is availble as a CodePage (http://
msdn2.microsoft.com/en-us/library/system.text.encodinginfo.aspx). How
does on set it in C# (or is there an overload in
System.Text.Encoding.GetString() which uses it?).

Thanks Again,
Jeff

> > I' working on an ASN.1 parser. The Content Octets (data values) are
> > stored in a byte[]. The conversion of byte[] to char[] is fairly
[quoted text clipped - 15 lines]
> Jon Skeet - <sk...@pobox.com>http://www.pobox.com/~skeet  Blog:http://www.msmvps.com/jon.skeet
> World class .NET training in the UK:http://iterativetraining.co.uk
Jon Skeet [C# MVP] - 20 Nov 2007 20:28 GMT
> > You don't build a string from bytes, you build it from Unicode
> > characters (or UTF-16 code points really).
[quoted text clipped - 5 lines]
> presented is based on a Stream (but I have a byte array). I was hoping
> for a more applicable answer.

Okay, to load a string from a Stream, you use a StreamReader with a
suitable Encoding.

> I also saw a T.61 string is availble as a CodePage (http://
> msdn2.microsoft.com/en-us/library/system.text.encodinginfo.aspx). How
> does on set it in C# (or is there an overload in
> System.Text.Encoding.GetString() which uses it?).

You can supply a code page to Encoding.GetEncoding.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.