As you've pointed out, the Normalize
method is not available on the String
class on Windows store apps.
However, this just calls the NormalizeString
function in the Windows API.
Even better, this function is in the approved list of Win32 and COM API functions usable in Windows Store apps.
That said, you'd make the following declarations:
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);
You'd then call it like so:
// 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();
String.Normalize
relies on native functions built in normaliz.dll. I dug a bit and found that it uses NormalizeString function. Since it is specific to Windows it is not available for Windows Store Apps. Unfortunatelly, I have no knowledge about alternatives. – GeodeticNormalizeString
is on the approved list of Win32 and COM API functions usable in Windows Store apps. – Oatcake