Char.IsPunctuation() Method in C#

The Char.IsPunctuation() method in C# determines whether a specified Unicode character is categorized as a punctuation mark. This method is useful for text processing, input validation, and character analysis tasks.

Syntax

Following is the syntax −

public static bool IsPunctuation(char ch);

Parameters

  • ch − The Unicode character to evaluate.

Return Value

Returns true if the character is a punctuation mark; otherwise, false.

Character Classification Punctuation ! ? . , ; : " ' ( ) [ ] { } - Returns True Letters A B C a b c X Y Z x y z Returns False Numbers 0 1 2 3 4 5 6 7 8 9 Returns False

Using Char.IsPunctuation() with Different Characters

Example with Non-Punctuation Character

using System;

public class Demo {
   public static void Main() {
      bool res;
      char val = 'q';
      Console.WriteLine("Value = " + val);
      res = Char.IsPunctuation(val);
      Console.WriteLine("Is the value a punctuation? = " + res);
   }
}

The output of the above code is −

Value = q
Is the value a punctuation? = False

Example with Punctuation Character

using System;

public class Demo {
   public static void Main() {
      bool res;
      char val = ',';
      Console.WriteLine("Value = " + val);
      res = Char.IsPunctuation(val);
      Console.WriteLine("Is the value a punctuation? = " + res);
   }
}

The output of the above code is −

Value = ,
Is the value a punctuation? = True

Testing Multiple Punctuation Characters

Example

using System;

public class Demo {
   public static void Main() {
      char[] chars = { '!', '?', '.', 'A', '5', '(', '}', '#', '@' };
      
      foreach (char ch in chars) {
         Console.WriteLine($"'{ch}' is punctuation: {Char.IsPunctuation(ch)}");
      }
   }
}

The output of the above code is −

'!' is punctuation: True
'?' is punctuation: True
'.' is punctuation: True
'A' is punctuation: False
'5' is punctuation: False
'(' is punctuation: True
'}' is punctuation: True
'#' is punctuation: True
'@' is punctuation: True

Common Use Cases

  • Text parsing − Identifying punctuation marks when processing sentences or documents.

  • Input validation − Checking if user input contains only specific character types.

  • String cleaning − Removing or replacing punctuation marks from text data.

Conclusion

The Char.IsPunctuation() method provides an efficient way to identify punctuation characters in Unicode text. It returns true for standard punctuation marks like periods, commas, and brackets, making it valuable for text processing and validation tasks.

Updated on: 2026-03-17T07:04:35+05:30

662 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements