In C#, IsNormalized() answers a yes or no question: is this string already in a standard Unicode form? With no argument it checks Form C, the same form Normalize() produces by default.
It is useful before normalizing: if the answer is true, you can skip the work and avoid making a new string. Plain ASCII text is always normalized. Text with combining accents typed separately, such as e + U+0301, is not in Form C.
This is an instance member of System.String. Call it on a string variable, such as text.IsNormalized(...). Calling it on a null variable throws NullReferenceException. It only reads the text. Strings are immutable, so the original string is never changed.
Syntax
Call it with no argument for Form C, or pass the form to check.
C#
using System.Text;
bool a = "\u00e9".IsNormalized(); // True
bool b = "e\u0301".IsNormalized(); // False
bool c = "e\u0301".IsNormalized(NormalizationForm.FormD); // True
Call
What it does
text.IsNormalized()
Is it in Form C?
text.IsNormalized(NormalizationForm.FormD)
Is it in Form D (letters and accents split)?
if (!text.IsNormalized()) text = text.Normalize();
Normalize only when needed.
A string can be normalized in one form and not in another, so always check the form you plan to use. Invalid Unicode (for example a lone surrogate half) throws ArgumentException.
Library declarations
C#
public bool IsNormalized();
public bool IsNormalized(NormalizationForm normalizationForm);
Parameters
Parameter
Description
normalizationForm
Optional. The form to check against. The default is FormC.
Return Value
Return Value
Description
true
The string is already in that form.
false
Calling Normalize with that form would change it.
C# Examples
Example 1 — Which Strings Are Normalized?
Check a precomposed letter, a decomposed letter, and a ligature against different forms.
C#
using System;
using System.Text;
class Program {
static void Main() {
Console.WriteLine("\u00e9".IsNormalized());
Console.WriteLine("e\u0301".IsNormalized());
Console.WriteLine("e\u0301".IsNormalized(NormalizationForm.FormD));
Console.WriteLine("\uFB01".IsNormalized(NormalizationForm.FormKC));
Console.WriteLine("hello".IsNormalized());
}
}
Output
True
False
True
False
True
How It Works
Already combined. U+00E9 is the Form C spelling of é, so the first check is True.
Split letter, wrong form.e + U+0301 is the Form D spelling, so it is not in Form C.
Right form, right answer. Checked against Form D, the same split string is normalized.
Ligatures and ASCII. The fi ligature is not in Form KC, which would split it into fi. Plain hello is normalized in every form.
Example 2 — Normalize Only When Needed
Check a name typed with a separate accent, normalize it, and check again.
C#
using System;
class Program {
static void Main() {
string name = "Jose\u0301";
Console.WriteLine(name.Length);
Console.WriteLine(name.IsNormalized());
if (!name.IsNormalized()) {
name = name.Normalize();
}
Console.WriteLine(name.Length);
Console.WriteLine(name.IsNormalized());
}
}
Output
5
False
4
True
How It Works
A separate accent.Jose plus U+0301 shows as José, but takes 5 chars.
Not Form C yet. The check is False, because the accent could be combined with the e.
Fix only if necessary. The if calls Normalize() just for text that needs it; already-clean names skip the work.
Combined and confirmed. After normalizing, the name has 4 chars and the check returns True.
Example 3 — Spot Look-Alike User Names
Two names look the same but were typed differently. Find out which one is not normalized, then compare them properly.
C#
using System;
class Program {
static void Main() {
string a = "Zo\u00eb";
string b = "Zoe\u0308";
Console.WriteLine(a == b);
Console.WriteLine(a.IsNormalized());
Console.WriteLine(b.IsNormalized());
Console.WriteLine(a == b.Normalize());
}
}
Output
False
True
False
True
How It Works
Same name on screen. Both display as Zoë: a uses U+00EB, while b uses e plus a combining diaeresis (U+0308).
A direct compare fails. The chars differ, so == is False, which could let two accounts share one visible name.
Find the odd one out.a is in Form C; b is not.
Normalize before storing. After normalizing b, the two names are equal. Saving every name in Form C prevents duplicates like this.
Frequently Asked Questions
It returns true when the string is already in the given Unicode normalization form (FormC by default) and false when Normalize would change it.
You can. If IsNormalized returns true, you skip creating a new string. Normalize also returns quickly for normalized input, so for small strings either way is fine.
Yes. Plain ASCII characters are normalized in FormC, FormD, FormKC, and FormKD.
Yes. A precomposed é is in FormC but not in FormD, and a decomposed e + accent is the opposite.