Tuesday, 15 June 2010

.net - How do I normalize a string? -



.net - How do I normalize a string? -

in .net can normalize (nfc, nfd, nfkc, nfkd) strings string.normalize() , there text.normalizationform enum.

in .net windows store apps, both not available. have looked in string class , in system.text , system.globalization namespaces, found nothing.

have missed something? how normalize strings in windows store apps?

does have thought why normalize method not made available store apps?

as you've pointed out, normalize method not available on string class on windows store apps.

however, calls normalizestring function in windows api.

even better, function in the approved list of win32 , com api functions usable in windows store apps.

that said, you'd create next 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 phone call so:

// form. norm_form form = ...; // string normalize. string unnormalized = "..."; // buffer required. int buffersize = normalizestring(form, unnormalized, unnormalized.length, null, 0); // allocate buffer. var buffer = new stringbuilder(buffersize); // normalize. normalizestring(form, unnormalized, unnormalized.length, buffer, buffer.length); // check , deed on errors if want. int error = marshal.getlastwin32error();

.net string unicode windows-store-apps unicode-normalization

No comments:

Post a Comment