tags:

views:

79

answers:

1

I have an C# application where I am storing the code point value of a Unicode character to be displayed when the user correctly matches a normal specific string.

The thing is that when I am storing the code point value directly (say, \uFB80) the application works fine. But when I am reading from a file or a variable that has the code point only (in this case FB80), I get a lot of wrongly rendered characters. Changing the stored value to \uFB80 or trying to add a "\u" in front of the value both results in the system reading it as \uFB80 which ends up having another wrong result.

What is the way around this?

XmlTextReader reader = new XmlTextReader("file.xml"); 
reader.Read(); 
reader.MoveToAttribute("glyph"); 

glyph = reader.Value; 
// glyph will be "FB80" 
// if xml file had "\uFB80", glyph will be "\\uFB80" 

richTextBox1.SelectionFont = "QCF_P604"; 
richTextBox1.AppendText(glyph); 
+1  A: 

dear Jalal, as I underestand You have a String (in file or within a TextBox) when You are parsing the string from the Box everything goes fine but when You are trying to read from a file you face with problem.

You have a XML document that You have strore the Characters Glyph in that. and each element of this XML (e.g: Item) has some attribute like Glyph. (the shape of character)

If You only want to display the Shape of the Character You're in serios wrong way. the only thing You should do is that write a simple method that gives a Decimal (or hex) value of character and return the Character.

Returned Character will display everywhere as a single character. so I strongly recommand ou to change the method ( this will speed up you app ).

// het a hex and return char (you can give it a large string or a single hexcode
// (hex without U just HexCode)
public static char ConvertHexToUnicode(string hexCode)
    {
        if (hexCode != string.Empty)
            return ((char)int.Parse(hexCode, NumberStyles.AllowHexSpecifier));

        char empty = new char();
        return empty;
    }//end

and for decimal value use the following code

 public static char ConvertDecimalToChar(Int64 decimalValue)
    {
        return ((char)int.Parse(decimalValue.ToString(), NumberStyles.Integer));
    }
Nasser Hadjloo
I used the hex version and it worked like a charm!! Thanks a lot Nasser.
Jalal Almutawa