C# Char IsControl() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Char

Definition

In C#, Char.IsControl returns true for Unicode control characters (category Cc)β€”for example tab, carriage return, and newline.

Ordinary printable letters and digits return false. Some controls are also whitespace; others are not meant to display.

This is a static member of System.Char. You call it with the type name, such as Char.IsControl(...) or char.IsControl(...). A char holds one 16-bit UTF-16 code unit.

Syntax

Pass the character to test.

C#
bool ok = Char.IsControl('\n');
CallWhat it does
Char.IsControl(c)True if c is a control character.
Char.IsControl(s, i)Tests s[i].

Space (U+0020) is whitespace but not a control character.

Library declarations
C#
public static bool IsControl(char c);
public static bool IsControl(string s, int index);

Parameters

ParameterDescription
cCharacter to test.
s, indexOptional string index overload.

Return Value

Return ValueDescription
trueControl character.
falseNot a control.

C# Examples

Example 1 — Newline Is Control

Compare newline with a letter.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine(Char.IsControl('\n'));
        Console.WriteLine(Char.IsControl('A'));
    }
}

How It Works

  1. Line feed. \n is a control character.
  2. Letter A. Printable, not control.
  3. Boolean pair. True then False.
  4. Filter use. Helpful when stripping invisible controls.

Example 2 — Tab Control, Space Not

Show the difference between tab and space.

C#
using System;

class Program {
    static void Main() {
        Console.WriteLine("tab control: " + Char.IsControl('\t'));
        Console.WriteLine("space control: " + Char.IsControl(' '));
        Console.WriteLine("space white: " + Char.IsWhiteSpace(' '));
    }
}

How It Works

  1. Tab is control. IsControl is true for \t.
  2. Space is not. U+0020 is outside Cc.
  3. Still whitespace. IsWhiteSpace remains true for space.
  4. Know the split. Avoid assuming all whitespace is control.

Example 3 — Remove Control Chars

Keep only non-control characters from a string.

C#
using System;

class Program {
    static void Main() {
        string raw = "A\tB\nC";
        string clean = "";
        foreach (char ch in raw) {
            if (!Char.IsControl(ch)) clean += ch;
        }
        Console.WriteLine(clean);
    }
}

How It Works

  1. Mixed input. Letters plus tab and newline.
  2. Negated test. Keep chars when IsControl is false.
  3. ABC result. Controls disappear.
  4. Spaces kept. Ordinary spaces would remain if present.

Frequently Asked Questions

Yes.
No. Space is whitespace but not Cc control.
Yes for and typically .
Many controls are non-printing, but always test with the API rather than assuming.
Yes: Char.IsControl(s, index).

Next: IsDigit()

Return true when the character is a Unicode decimal digit with System.Char.

IsDigit() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P πŸ”—

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

7 people found this page helpful