Vaishali
Vaishali

Reputation: 131

Populate escape sequence character in Combo Box shows empty spaces

I am binding a combo box with all the characters from ttf file. Combo box displays empty space for some of the characters like \n \r \t \a etc. I am not able to find the reason why it does so.

Here is my code to populate all symbols

var families = Fonts.GetFontFamilies(new Uri(fontFilePath));
            foreach (FontFamily family in families)
            {
                var typefaces = family.GetTypefaces();
            foreach (Typeface typeface in typefaces)
            {
                GlyphTypeface glyph;
                typeface.TryGetGlyphTypeface(out glyph);
                IDictionary<int, ushort> characterMap = glyph.CharacterToGlyphMap;

                foreach (var item in characterMap.Values)
                {
                    char temp = Convert.ToChar(item);
                    string str = string.Format("{0}", temp);
                    if (!listOfString.Contains(str))
                    {
                        listOfString.Add(str);
                    }
                }
            }
        }
        listOfString.Sort();
        ddlSymbols.ItemsSource = listOfString;

Any help would be highly appreciated. Thanks in advance.

Upvotes: 0

Views: 933

Answers (1)

Nicolas R
Nicolas R

Reputation: 14619

In C#, some of the characters are called "Escape sequences" and are special characters.

  • \' (UTF-16: \u0027) = allow to enter a ' in a character literal, e.g. '\''
  • \" (UTF-16: \u0022) = allow to enter a " in a string literal, e.g. "this is the double quote (\") character"
  • \ \u005c allow to enter a \ character in a character or string literal, e.g. '\' or "this is the backslash (\) character"
  • \0 (UTF-16: \u0000) = allow to enter the character with code 0
  • \a (UTF-16: \u0007) = alarm (usually the HW beep)
  • \b (UTF-16: \u0008) = back-space
  • \f (UTF-16: \u000c) = form-feed (next page)
  • \n (UTF-16: \u000a) = line-feed (next line)
  • \r (UTF-16: \u000d) = carriage-return (move to the beginning of the line)
  • \t (UTF-16: \u0009) = (horizontal-) tab
  • \v (UTF-16: \u000b) = vertical-tab

So when you map your characters, their special behaviour is used.

Upvotes: 1

Related Questions