Is there a way in .Net to find out, what Unicode name certain character has?
If not, is there a library that can do this?
Is there a way in .Net to find out, what Unicode name certain character has?
If not, is there a library that can do this?
If you use Process Monitor to look at the files accessed by charmap.exe, you'll see that it opens a file named C:\Windows\system32\getuname.dll. This file contains the character names in its resources (actually the resources themselves are in a .mui file in a culture-specific subdirectory).
So all you have to do is get the names from this file, using the LoadString API. I wrote a helper class to do it:
public class Win32ResourceReader : IDisposable
{
private IntPtr _hModule;
public Win32ResourceReader(string filename)
{
_hModule = LoadLibraryEx(filename, IntPtr.Zero, LoadLibraryFlags.AsDataFile | LoadLibraryFlags.AsImageResource);
if (_hModule == IntPtr.Zero)
throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());
}
public string GetString(uint id)
{
var buffer = new StringBuilder(1024);
LoadString(_hModule, id, buffer, buffer.Capacity);
if (Marshal.GetLastWin32Error() != 0)
throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());
return buffer.ToString();
}
~Win32ResourceReader()
{
Dispose(false);
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public void Dispose(bool disposing)
{
if (_hModule != IntPtr.Zero)
FreeLibrary(_hModule);
_hModule = IntPtr.Zero;
}
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int LoadString(IntPtr hInstance, uint uID, StringBuilder lpBuffer, int nBufferMax);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hReservedNull, LoadLibraryFlags dwFlags);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool FreeLibrary(IntPtr hModule);
[Flags]
enum LoadLibraryFlags : uint
{
AsDataFile = 0x00000002,
AsImageResource = 0x00000020
}
}
You can use it like this:
string path = @"C:\Windows\System32\getuname.dll";
using (var reader = new Win32ResourceReader(path))
{
string name = reader.GetString(0xA9);
Console.WriteLine(name); // Copyright Sign
}
It isn't a built-in feature in .NET. You can find out from Charmap.exe, it displays the codepoint name in the status bar. If you need that in your own program you could compile the Unicode Character Database into your app.
I don't think there's anything built into .NET to identify this... But there is a Unicode character database.
As Hans Passant and MichaelBray said, .NET does not provide any built-in feature to get the Unicode name of characters.
You can use the Unicode Character Database which at http://unicode.org/ucd - today it contains the complete information of all Unicode 5.2 characters (annex #44).
Another alternative is to use the Character Map in Windows which you can access via Start\App Programs\Accessories\System Tools\Character Map (Win+R => charmap)
You can also use Unicode Converter Tools, which is a Open Source tool at http://unicode.codeplex.com it also provides a user interface for getting information and also its use from Unicode UCD (annex #44) the keynote of this software for You is that you can add the EnterpriseAppUnit dll of this aplication to your application and use the provided API.
This Assembly contain some static methods that takes a 'char` and returns the Name, HexCode, Decimal Code, etc.