C# Char IsWhiteSpace() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Char

Definition

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(' ');
CallWhat 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

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

Return Value

Return ValueDescription
trueWhitespace.
falseNot 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'));
    }
}

How It Works

  1. Ordinary space. Counts as whitespace.
  2. Letter A. Not whitespace.
  3. Two prints. True then False.
  4. 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('.'));
    }
}

How It Works

  1. Tab. Horizontal tab is whitespace.
  2. Newline. Line feed is whitespace.
  3. Period. Punctuation is not whitespace.
  4. 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));
    }
}

How It Works

  1. Index walk. Use the string overload of IsWhiteSpace.
  2. Skip blanks. Stop at the first non-space.
  3. Index 2. Two leading spaces are consumed.
  4. 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.

Next: Parse()

Convert a length-1 string to a char, or throw if invalid with System.Char.

Parse() 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.

12 people found this page helpful