In C#, Char.IsWhiteSpace returns true for Unicode whitespace characters—space, tab, carriage return, newline, and more.
Use it when trimming or splitting logic needs to treat all whitespace alike, not only ' '.
This is a static member of System.Char. You call it with the type name, such as Char.IsWhiteSpace(...) or char.IsWhiteSpace(...). A char holds one 16-bit UTF-16 code unit.
Syntax
Pass the character to test.
C#
bool ok = Char.IsWhiteSpace(' ');
Call
What it does
Char.IsWhiteSpace(c)
True if c is whitespace.
Char.IsWhiteSpace(s, i)
Tests s[i].
A regular letter or digit returns false.
Library declarations
C#
public static bool IsWhiteSpace(char c);
public static bool IsWhiteSpace(string s, int index);
Parameters
Parameter
Description
c
Character to test.
s, index
Optional string index overload.
Return Value
Return Value
Description
true
Whitespace.
false
Not whitespace.
C# Examples
Example 1 — Space and Letter
Compare a space with a letter.
C#
using System;
class Program {
static void Main() {
Console.WriteLine(Char.IsWhiteSpace(' '));
Console.WriteLine(Char.IsWhiteSpace('A'));
}
}
Output
True
False
How It Works
Ordinary space. Counts as whitespace.
Letter A. Not whitespace.
Two prints. True then False.
Starter check. Confirms the common case.
Example 2 — Tab and Newline
Show that control whitespace counts.
C#
using System;
class Program {
static void Main() {
Console.WriteLine(Char.IsWhiteSpace('\t'));
Console.WriteLine(Char.IsWhiteSpace('\n'));
Console.WriteLine(Char.IsWhiteSpace('.'));
}
}
Output
True
True
False
How It Works
Tab. Horizontal tab is whitespace.
Newline. Line feed is whitespace.
Period. Punctuation is not whitespace.
Broader than space. Do not only test equality to ' '.
Example 3 — Skip Leading Spaces
Advance an index while whitespace remains.
C#
using System;
class Program {
static void Main() {
string s = " hi";
int i = 0;
while (i < s.Length && Char.IsWhiteSpace(s, i)) i++;
Console.WriteLine("start at " + i);
Console.WriteLine(s.Substring(i));
}
}
Output
start at 2
hi
How It Works
Index walk. Use the string overload of IsWhiteSpace.
Skip blanks. Stop at the first non-space.
Index 2. Two leading spaces are consumed.
Remainder hi. Substring shows the trimmed view.
Frequently Asked Questions
Yes. Tabs and many other Unicode spaces count.
Yes for and among others.
IsWhiteSpace works on characters, not whole strings. Use string.IsNullOrWhiteSpace for strings.
No. It tests one character. Use Trim for whole strings.
Many Unicode space separators are included; check docs for edge cases.