
How can you determine if a string instance in your C# program is normalized? In Unicode strings, there are different normalization forms that determine how certain characters are represented. With the IsNormalized method you can test for normalized character data.

First, this program declares a const string with the value á. With the Normalize and IsNormalized methods, only non-ASCII characters are affected. We then Normalize to FormC and also FormD. The parameterless IsNormalized method returns true if the string is normalized to FormC. It returns false if the normalization form is FormD. You can also pass an argument to IsNormalized; in this case, that specific normalization form is checked for.
This C# example program uses the IsNormalized method. IsNormalized tests for normalized character data.
Program that uses IsNormalized [C#]
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
The IsNormalization method addresses the need for programmers to determine the normalization status of a string. In the .NET Framework, normalization is necessary when interoperating with other systems; typically, you can just leave strings in their default normalization format. For more information, check out the Normalize method.
Normalize Method String Type