C# | String.IsNormalized Method
Last Updated :
06 Jan, 2022
IsNormalized() method is used to check whether the given string is in a particular Unicode normalization form or not. If the given string is in the particular normalized form, then this method returns true. Otherwise, return false.
There are
two methods in the overload list of this method as follows:
- IsNormalized()
- IsNormalized(NormalizationForm)
Important Points:
- Some Unicode characters have multiple equivalent binary representations which complicate the searching, sorting, matching and other operations.
- The Unicode standard defines a process termed as normalization which returns one binary representation when given any of the equivalent binary representations of a character. Normalization can be performed with several algorithms, called normalization forms, that obey different rules.
- .NET currently supports normalization forms C, D, KC, and KD.
IsNormalized()
This method is used to check whether the given string is in Unicode normalization form C or not. If the string is in Unicode normalized form C then this method return true, otherwise false.
Syntax:
public bool IsNormalized ();
Return Value: The return type of this method is
System.Boolean. This method returns true when the given string is in normalization form C and return false when the given string is not in the normalization form i.e C.
Exception: If the current instance contains invalid Unicode characters, then this method will give
ArgumentException.
Example:
CSharp
// C# program to illustrate the
// IsNormalized() method
using System;
using System.Text;
class GFG {
// Main method
static public void Main()
{
// string
string str1 = "Hello, Geeks!";
bool value;
// check the given string is
// in normalized form or not
// using IsNormalized() method
value = str1.IsNormalized();
// Display the data
Console.WriteLine("String is : {0}", str1);
Console.WriteLine("Is str1 string is in normalized form?: {0}",
value);
}
}
Output:
String is : Hello, Geeks!
Is str1 string is in normalized form?: True
Note: The IsNormalized method returns false as it will come across the first non-normalized character in a string. So, if a string contains non-normalized characters followed by invalid Unicode characters, the Normalize method will throw an
ArgumentException although IsNormalized returns
false.
IsNormalized(NormalizationForm)
This method is used to check whether the given string is in the specified Unicode normalization form or not. If the given string is in specified Unicode normalization form then this method will return true, otherwise false.
Syntax:
public bool IsNormalized (NormalizationForm nform);
Here,
nform is a Unicode normalization form.
Return Value: The return type of this method is
System.Boolean. This method returns
true if this string is in the normalization form specified by the
nform parameter. Otherwise, returns
false.
Exception: This method will give
ArgumentException if the current instance contains invalid Unicode characters.
Example:
CSharp
// C# program to illustrate the
// IsNormalized(NormalizationForm) method
using System;
using System.Text;
class Sample {
// Main method
public static void Main()
{
// create and initialize string
string str1 = "GeeksforGeeks!";
// Display and check the given string
// is in C, D, KC, and KD normalized form
// Using IsNormalized(NormalizationForm) method
Console.WriteLine("Is string str1 is normalized to form C - {0}",
str1.IsNormalized(NormalizationForm.FormC));
Console.WriteLine("Is string str1 is normalized to form D - {0}",
str1.IsNormalized(NormalizationForm.FormD));
Console.WriteLine("Is string str1 is normalized to form KC - {0}",
str1.IsNormalized(NormalizationForm.FormKC));
Console.WriteLine("Is string str1 is normalized to form KD - {0}",
str1.IsNormalized(NormalizationForm.FormKD));
}
}
Output:
Is string str1 is normalized to form C - True
Is string str1 is normalized to form D - True
Is string str1 is normalized to form KC - True
Is string str1 is normalized to form KD - True
Reference: https://docs.microsoft.com/en-us/dotnet/api/system.string.isnormalized?view=netframework-4.7.2
Similar Reads
C# String IsNullOrEmpty() Method
In C#, IsNullOrEmpty() is a string method. It is used to check whether the specified string is null or an Empty string. A string will be null if it has not been assigned a value. A string will be empty if it is assigned ââ or String.Empty (A constant for empty strings).Example 1: Using IsNullOrEmpty
2 min read
C# | String.Contains() Method
In C#, the String.Contains() method is used to check whether a substring exists within a given string. It returns a Boolean value (true or false) indicating whether the substring is found. By default, the method performs a case-sensitive comparison.Example 1: Here, we are using the String.Contains()
3 min read
C# String CompareOrdinal() Method
In C#, CompareOrdinal() is a method of the String class. This method is used to compare the two specified string objects or substrings using the numerical values (Unicode) of the corresponding Char objects in each string or substring. It performs a case-sensitive and culture-insensitive comparison.O
4 min read
C# | Char.ToString() Method
In C#, Char.ToString() is a System.Char struct method which is used to convert the value of this instance to its equivalent string representation. This method can be overloaded by passing different type of arguments to it. Char.ToString(IFormatProvider) Method Char.ToString(Char) Method Char.ToStrin
2 min read
C# | Decimal.ToString Method | Set -1
Decimal.ToString() Method is used to convert the numeric value of the current instance to its equivalent string representation using the specified culture-specific format information. There are 4 methods in the overload list of this method as follows: ToString() Method ToString(IFormatProvider) Meth
3 min read
C# | Decimal.ToString Method | Set -2
Decimal.ToString() Method is used to convert the numeric value of the current instance to its equivalent string representation. There are 4 methods in the overload list of this method as follows: ToString(String) Method ToString() Method ToString(IFormatProvider) Method ToString(String, IFormatProvi
2 min read
C# String CopyTo() Method
In C#, the CopyTo() is a method of String Class. It is used to copy a specified number of characters from a specified position in the string and it copies the characters of this string into an array of Unicode characters.Example 1: Using the CopyTo() method to copy characters from a string to a char
2 min read
C# String.IndexOf( ) Method | Set - 1
In C#, the IndexOf() method is a String method. Used to find the zero-based index of the first occurrence of a specified character or string within the current instance of the string. The method returns -1 if the character or string is not found. This method can be overloaded by passing different pa
6 min read
C# | Char.IsControl(String, Int32) Method
This method is used to indicates whether the character at the specified position in a specified string is categorized as a control character. Syntax: public static bool IsControl (string s, int index); Parameters: s: It is the String. index: It is the character position in s. Return Value: This meth
3 min read
C# | Double.ToString() Method | Set - 1
Double.ToString() Method is used to convert the numeric value of the current instance to its equivalent string representation. There are 4 methods in the overload list of this method as follows: ToString(String) Method ToString() Method ToString(IFormatProvider) Method ToString(String, IFormatProvid
3 min read