Chr(), ChrW()?

  • Thread starter Thread starter Guinness Mann
  • Start date Start date
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
 
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.
 
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
 
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
 
Back
Top