5

I'm working with C# .Net

I would like to know how to convert a Unicode form string like "\u1D0EC" (note that it's above "\uFFFF") to it's symbol... ""

Thanks For Advance!!!

Jack
  • 667
  • 3
  • 9
  • 13
  • Isn't unicode maximum value only FFFF? What's the meaning of unicode 1D0EC? – Aviad P. Jan 02 '10 at 19:14
  • the closest solution that i've found was this one: http://stackoverflow.com/questions/1615559/converting-unicode-strings-to-escaped-ascii-string but it worked only for below unicode "\uFFFF" – Jack Jan 02 '10 at 19:14
  • What do you mean to its symbol? During display time the symbol gets mapped to its visual representation. Do you want to convert to UTF8? to a particular encoding? Joel Spolsky has a good article on Unicode - it is confusing. – Hamish Grubijan Jan 02 '10 at 19:15
  • the meaning is: http://www.fileformat.info/info/unicode/char/1d0ec/index.htm unicode can be above FFFF – Jack Jan 02 '10 at 19:16
  • i dont care not to see it in visual representation just need the string with the square in it. in fileformat.com they have a "Browser Test Page" where you can see the matching square – Jack Jan 02 '10 at 19:18

4 Answers4

7

That Unicode codepoint is encoded in UTF32. .NET and Windows encode Unicode in UTF16, you'll have to translate. UTF16 uses "surrogate pairs" to handle codepoints above 0xffff, a similar kind of approach as UTF8. The first code of the pair is 0xd800..dbff, the second code is 0xdc00..dfff. Try this sample code to see that at work:

using System;
using System.Text;

class Program {
  static void Main(string[] args) {
    uint utf32 = uint.Parse("1D0EC", System.Globalization.NumberStyles.HexNumber);
    string s = Encoding.UTF32.GetString(BitConverter.GetBytes(utf32));
    foreach (char c in s.ToCharArray()) {
      Console.WriteLine("{0:X}", (uint)c);
    }
    Console.ReadLine();
  }
}
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
2

Convert each sequence with int.Parse(String, NumberStyles) and char.ConvertFromUtf32:

string s = @"\U1D0EC";
string converted = char.ConvertFromUtf32(int.Parse(s.Substring(2), NumberStyles.HexNumber));
bruno conde
  • 47,767
  • 15
  • 98
  • 117
1

I have recently push my FOSS Uncode Converter at Codeplex (http://unicode.codeplex.com)

you can convert whatever you want to Hex code and from Hex code to get the right character, also there is a full information character database.

I use this code

public static char ConvertHexToUnicode(string hexCode)
    {
        if (hexCode != string.Empty)
            return ((char)int.Parse(hexCode, NumberStyles.AllowHexSpecifier));

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

you can see entire code on the http://unicode.codeplex.com/

Renaud Bompuis
  • 16,596
  • 4
  • 56
  • 86
Nasser Hadjloo
  • 12,312
  • 15
  • 69
  • 100
0

It appears you just want this in your code... you can type it as a string literal using the escape code \Uxxxxxxxx (note that this is a capital U, and there must be 8 digits). For this example, it would be: "\U0001D0EC".

porges
  • 30,133
  • 4
  • 83
  • 114