Char.IsControl(String, Int32) Method in C#

CsharpProgrammingServer Side Programming

The Char.IsControl(String, Int32) method in C# is used to indicate whether the character at the specified position in a specified string is categorized as a control character.


public static bool IsControl (string str, int index);

Above, str is a string. The index parameter is the position of the character to evaluate in str.

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


using System;
using System.Globalization;
public class Demo {
   public static void Main(){
      string val = "hjk9878hj";
      Console.WriteLine("String = "+val);
      UnicodeCategory unicode = Char.GetUnicodeCategory(val, 4);
      Console.WriteLine("The value at specific index = "+unicode);
      bool res = Char.IsControl(val, 4);
      if (res)
         Console.WriteLine("Control character found!");
         Console.WriteLine("Control character isn't there");


This will produce the following output −

String = hjk9878hj
The value at specific index = DecimalDigitNumber
Control character isn't there
Updated on 04-Nov-2019 08:06:22