正如您所指出的,该Normalize
方法在 Windows 商店应用程序的String
类中不可用。
但是,这只是调用Windows API 中的NormalizeString
函数。
更好的是,这个函数在 Windows 应用商店应用程序中可用的 Win32 和 COM API 函数的批准列表中。
也就是说,您将做出以下声明:
public enum NORM_FORM
{
NormalizationOther = 0,
NormalizationC = 0x1,
NormalizationD = 0x2,
NormalizationKC = 0x5,
NormalizationKD = 0x6
};
[DllImport("Normaliz.dll", CharSet = CharSet.Unicode, ExactSpelling = true,
SetLastError = true)
public static extern int NormalizeString(NORM_FORM NormForm,
string lpSrcString,
int cwSrcLength,
StringBuilder lpDstString,
int cwDstLength);
然后你会这样称呼它:
// The form.
NORM_FORM form = ...;
// String to normalize.
string unnormalized = "...";
// Get the buffer required.
int bufferSize =
NormalizeString(form, unnormalized, unnormalized.Length, null, 0);
// Allocate the buffer.
var buffer = new StringBuilder(bufferSize);
// Normalize.
NormalizeString(form, unnormalized, unnormalized.Length, buffer, buffer.Length);
// Check for and act on errors if you want.
int error = Marshal.GetLastWin32Error();