PC Review


Reply
Thread Tools Rate Thread

convert Int32 Unicode character code to its value

 
 
John
Guest
Posts: n/a
 
      8th Oct 2008
I have a simple question which, surprisingly a google search nor MSDN
can help me with. What is the best stream to use to parse a string,
character by character. All the streams return Int32, but I cannot find
a way to convert the Int32 to a character value. For instance,
StringReader.Read("1") returns 49, the Unicode character code. How do I
convert this unicode code to its value '1'?

Also, off the main question, but here are a couple more:

1) Why doesn't StringReader take an Encoding?
2) If StringReader does not take an Encoding, how does it actually work?
3) If String has a Trim function, why isn't there an
Encoding.xxx.IsSpace(Int32 ch)?

thanks very much in advance
 
Reply With Quote
 
 
 
 
Luc E. Mistiaen
Guest
Posts: n/a
 
      8th Oct 2008
you can try with a StreamReader and an Encoding of 'utf-32' (code page
12000).


/LM

"John" <(E-Mail Removed)> wrote in message
news:eRLNJ%(E-Mail Removed)...
>I have a simple question which, surprisingly a google search nor MSDN can
>help me with. What is the best stream to use to parse a string, character
>by character. All the streams return Int32, but I cannot find a way to
>convert the Int32 to a character value. For instance,
>StringReader.Read("1") returns 49, the Unicode character code. How do I
>convert this unicode code to its value '1'?
>
> Also, off the main question, but here are a couple more:
>
> 1) Why doesn't StringReader take an Encoding?
> 2) If StringReader does not take an Encoding, how does it actually work?
> 3) If String has a Trim function, why isn't there an
> Encoding.xxx.IsSpace(Int32 ch)?
>
> thanks very much in advance



 
Reply With Quote
 
John
Guest
Posts: n/a
 
      8th Oct 2008
Peter Duniho wrote:
> Why not just enumerate all the characters in the string? For example:
>
> string strInput = "my string";
>
> foreach (char chInput in strInput)
> {
> // do something with each character
> }
>
> Is there some specific reason you want to use StringReader?


Well, the code uses a system of building token types and objects out of
the string. I am porting some C++ code that uses putback on the stream
during the processing which can be converted to Peek(). Your suggestion
is valid but I'm not sure it's going to work.

> Second, the Encoding class has _no_ methods of that nature. Why would
> you expect to find an IsSpace() method in the Encoding class, when there
> aren't any methods to classify characters?
>
> You can, of course, call Char.IsWhiteSpace() on characters once you've
> got a valid UTF-16 character to look at.
>


Of course, the Char class, how did I miss that, thanks very much.

Sound advice as usual Peter.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I use Excel to convert Chinese character into Unicode? =?Utf-8?B?UmljaGFyZCBIc2lhbw==?= Microsoft Excel Misc 0 22nd Sep 2005 10:06 AM
convert Character to Unicode in VB.NET =?Utf-8?B?QW1yaXQ=?= Microsoft Access Forms 0 16th Mar 2005 09:33 AM
Convert and Int32 value into a Character Joshua Russell Microsoft C# .NET 3 2nd Jun 2004 01:23 AM
Convert character reference to unicode/utf-8 Daniel Köster Microsoft VB .NET 2 24th May 2004 12:40 PM
convert chiness character to unicode ws Microsoft Dot NET Framework 1 20th Mar 2004 01:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:44 PM.