I was having an issue with the Utf7Encoding class truncating the '+4' sequence. I would be very interested to know why this was happening. I tried Utf8Encoding for getting string from the byte[] array and it seem to work honky dory. Are there any known issues like that with Utf8? Essentially I use the output produced by this conversion to construct html out of rtf string.
Here is the snippet:
UTF7Encoding utf = new UTF7Encoding();
UTF8Encoding utf8 = new UTF8Encoding();
string test = "blah blah 9+4";
char[] chars = test.ToCharArray();
byte[] charBytes = new byte[chars.Length];
for (int i = 0; i < chars.Length; i++)
{
charBytes[i] = (byte)chars[i];
}
string resultString = utf8.GetString(charBytes);
string resultStringWrong = utf.GetString(charBytes);
Console.WriteLine(resultString); //blah blah 9+4
Console.WriteLine(resultStringWrong); //blah 9
Converting to byte array through char array like that does not work. If you want the strings as charset-specific
byte[]
do this:Output: