Seb*_*zus 10 .net string unicode unicode-normalization windows-store-apps
在.NET中,你可以标准化(NFC,NFD,NFKC,NFKD)字符串,String.Normalize()
并且有一个 Text.NormalizationForm
枚举.
在.NET for Windows Store应用程序中,两者都不可用.我查看了String
类System.Text
和System.Globalization
名称空间,但没有发现任何内容.
我错过了什么吗?如何规范化Windows应用商店应用中的字符串?
有没有人知道为什么这个Normalize
方法不适用于Store Apps?
正如您所指出的,该Normalize
方法在Windows商店应用程序的String
类上不可用.
然而,这只是调用NormalizeString
函数在Windows的API中.
更好的是,此功能位于Windows Store应用程序中可用的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);
Run Code Online (Sandbox Code Playgroud)
然后你会这样称呼它:
// 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();
Run Code Online (Sandbox Code Playgroud)