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');
Call
What 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
Parameter
Description
c
Character to test.
s, index
Optional string index overload.
Return Value
Return Value
Description
true
Control character.
false
Not 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'));
}
}
Output
True
False
How It Works
Line feed. \n is a control character.
Letter A. Printable, not control.
Boolean pair. True then False.
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(' '));
}
}
Output
tab control: True
space control: False
space white: True
How It Works
Tab is control. IsControl is true for \t.
Space is not. U+0020 is outside Cc.
Still whitespace. IsWhiteSpace remains true for space.
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);
}
}
Output
ABC
How It Works
Mixed input. Letters plus tab and newline.
Negated test. Keep chars when IsControl is false.
ABC result. Controls disappear.
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.