0

I am getting this weird occurrence when using unicodes in my application. I have a list of random unicodes which I then randomly assign to an object.

var icons = new List<string> { "\uf022", "\uf039", "\uf02b", "\uf1b2", "\uf07b" };

When I debug the object the Object.Icon property shows "." which is the correct value for unicode. When I display the unicodes on a XAML page the correct icons are displayed.

Unicode from application list

So when I got this working I wanted to move the unicode values into the database instead of making it random. But now when I debug the object the Object.Icon property shows "\\unicodevalue" i.e "\uf022".

enter image description here

When displaying this value on the XAML page, its being displayed as the text value \uf022 instead of an icon.

What is the difference between the strings in the icons list and having the string value in the database?

3
  • 1
    You'll need to debug the code that puts these values in the database and retrieves them, as that's where things are going wrong. Just observing the end result only tells you that there's a problem, not what it is. Commented Jun 14, 2018 at 10:33
  • The values in the database are the exact same values that are in the random icons list though. This code is on retrieval. Commented Jun 14, 2018 at 10:34
  • Then you've narrowed it down to the code that retrieves things, I'd say. To be clear: the string consisting of the single character U+F022 is not the same string as the string \uf022. Your database can (probably) store either, but make sure you're not confounded by tools that don't display things accurately. If using SQL Server, for example, use DATALENGTH to get the string size in bytes, and things like CONVERT(VARBINARY(MAX), [column]) to see the actual contents in code points. (Note also that U+F022 is an unassigned private use character and can be displayed as whatever.) Commented Jun 14, 2018 at 10:37

1 Answer 1

2

The unicode sequences in the database have their backslash escaped, so "\\uf042" is really 6 characters altogether: the backslash, "u", "f", "0", "4" and "2".

The unicode sequences in your code however, are really just one character as far as C# is concerned, They are literals of unicode code points.

To change from the values in your database to individual unicode code points, try the Char.ConvertFromUtf32 method.

Sign up to request clarification or add additional context in comments.

1 Comment

I've changed the code that saved the unicode into the database to instead save the decimal value. I can then use Char.ConvertFromUtf32 to covert to the icon.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.