Chr(), ChrW()?

G

Guinness Mann

I have some bytes that are representations of ascii characters. Is
there a C# equivalent of the VB Chr() and ChrW() functions?

How do I turn these byte-strings into characters?

Thanks,

-- Rick
 
G

Girish Bharadwaj

Guinness said:
I have some bytes that are representations of ascii characters. Is
there a C# equivalent of the VB Chr() and ChrW() functions?

How do I turn these byte-strings into characters?

Thanks,

-- Rick
If you know the encoding of these byte strings (UTF8, ASCII) .. You can
use the corresponding XXXEncoding class to turn them to real Strings. is
that what you are looking for?

In your case, it will be ASCIIEncoding.GetString() class might suffice.
 
G

Guinness Mann

girishb@nowhere said:
If you know the encoding of these byte strings (UTF8, ASCII) .. You can
use the corresponding XXXEncoding class to turn them to real Strings. is
that what you are looking for?

In your case, it will be ASCIIEncoding.GetString() class might suffice.

They're sort of UTF8, but the data has been screwed with so that it is
not necessarily all of the same encoding. My brother (who is doing the
work) is currently pulling ascii representations of integers off of the
stream, converting them to int32's and then testing them to see if they
are in the ascii range and then, if so, converting them one character at
a time. If they look like wide chars, he tries to convert them to wide.

That's why he was looking for a function that he could pass a character
at a time -- something like ChrW().

-- Rick
 
M

Mattias Sjögren

Rick,
That's why he was looking for a function that he could pass a character
at a time -- something like ChrW().

The C# equivalent of ChrW is to just cast the integer value to a char.

char c = (char)i;



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top