Char.GetUnicodeCategory(String, Int32) Method with Examples in C#


The Char.GetUnicodeCategory(String, Int32) method in C# categorizes the character at the specified position in a specified string into a group identified by one of the UnicodeCategory values.

Syntax

Following is the syntax −

public static System.Globalization.UnicodeCategory GetUnicodeCategory (string str, int index);

Above, str is a string, whereas the index is the character position in str.

Example

Let us now see an example to implement the Char.GetUnicodeCategory(String, Int32) method −

using System;
using System.Globalization;
public class Demo {
   public static void Main(){
      string val = "amit";
      UnicodeCategory unicode = Char.GetUnicodeCategory(val, 2);
      Console.WriteLine("The value at specific index = "+unicode);
   }
}

Output

This will produce the following output −

LowercaseLetter

Example

Let us now see another example −

using System;
using System.Globalization;
public class Demo {
   public static void Main(){
      string val = "hjk9878hj";
      UnicodeCategory unicode = Char.GetUnicodeCategory(val, 4);
      Console.WriteLine("The value at specific index = "+unicode);
   }
}

Output

This will produce the following output −

The value at specific index = DecimalDigitNumber

Updated on: 12-Nov-2019

118 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements