C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Then: We print, with Console.WriteLine, the resulting strings to the screen as we go along.
ConsoleHere: The first call to Normalize uses the NormalizationForm.FormC enum in its implementation. This detail can be seen in IL Disassembler.
IL DisassemblerInfo: The results have 2 forms: the "a" with the accent on top, and an ASCII "a" with a single-quote character following it.
Finally: In FormD and FormKD, the single-quote character follows the accented letter.
C# program that uses Normalize method
using System;
using System.Text;
class Program
{
static void Main()
{
const string input = "á";
string val2 = input.Normalize();
Console.WriteLine(val2);
string val3 = input.Normalize(NormalizationForm.FormD);
Console.WriteLine(val3);
string val4 = input.Normalize(NormalizationForm.FormKC);
Console.WriteLine(val4);
string val5 = input.Normalize(NormalizationForm.FormKD);
Console.WriteLine(val5);
}
}
Output
á
a '
á
a '
Example: We declare a string that has an accent in it. With Normalize and IsNormalized, only non-ASCII characters are affected.
And: IsNormalized returns true if the string is normalized to FormC. It returns false if the form is FormD.
BoolNote 2: You can also pass an argument to IsNormalized. In this case, that specific normalization form is checked.
C# program that uses IsNormalized
using System;
using System.Text;
class Program
{
static void Main()
{
const string input = "á";
string val2 = input.Normalize();
string val3 = input.Normalize(NormalizationForm.FormD);
Console.WriteLine(input.IsNormalized());
Console.WriteLine(val2.IsNormalized());
Console.WriteLine(val3.IsNormalized());
Console.WriteLine( val3.IsNormalized(NormalizationForm.FormD));
}
}
Output
True
True
False
True
Tip: There is no reason to call Normalize if you are just using ASCII or if you are not interoperating with another Unicode form.
Typically: You can ignore IsNormalized and just leave strings in their default normalization format.