private string Convert(int asciiCode)
{
Encoding ascii = Encoding.UTF32;
char c = (char)asciiCode;
Byte[] b = ascii.GetBytes(c.ToString());
return ascii.GetString((b));
}
{
Encoding ascii = Encoding.UTF32;
char c = (char)asciiCode;
Byte[] b = ascii.GetBytes(c.ToString());
return ascii.GetString((b));
}
2 comments:
doesnt work!! getString accepts ubyte [] not a byte[], can someone please update this post.
Maybe this works better:
private string ConvertAsciiToUnicode(string theAsciiString) {
// Create two different encodings.
Encoding aAsciiEncoding = Encoding.ASCII;
Encoding aUnicodeEncoding = Encoding.Unicode;
// Convert the string into a byte[].
byte[] aAsciiBytes = aAsciiEncoding.GetBytes(theAsciiString);
// Perform the conversion from one encoding to the other.
byte[] aUnicodeBytes = Encoding.Convert(aAsciiEncoding, aUnicodeEncoding,
aAsciiBytes);
// Convert the new byte[] into a char[] and then into a string.
char[] aUnicodeChars = new
char[aUnicodeEncoding.GetCharCount(aUnicodeBytes, 0, aUnicodeBytes.Length)];
aUnicodeEncoding.GetChars(aUnicodeBytes, 0, aUnicodeBytes.Length,
aUnicodeChars, 0);
string aUnicodeString = new string(aUnicodeChars);
return aUnicodeString;
}
Post a Comment