Check whether the specified Unicode character is a punctuation mark in C#

The Char.IsPunctuation() method in C# determines whether a specified Unicode character is classified as a punctuation mark. This method returns true if the character belongs to any punctuation category, otherwise it returns false.

Punctuation marks include characters like periods, commas, semicolons, exclamation points, question marks, brackets, and other symbols used for punctuation in text.

Syntax

Following is the syntax for the Char.IsPunctuation() method −

public static bool IsPunctuation(char c)

Parameters

  • c − The Unicode character to evaluate.

Return Value

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

Example - Non-Punctuation Character

The following example checks if the character 'q' is a punctuation mark −

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 - Punctuation Character

The following example checks if the comma character is a punctuation mark −

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

Example - Testing Multiple Characters

The following example demonstrates testing various characters to identify which ones are punctuation marks −

using System;

public class Demo {
   public static void Main() {
      char[] characters = { 'A', '!', '?', '5', ';', '[', '}', '@' };
      
      Console.WriteLine("Character\tIs Punctuation");
      Console.WriteLine("-------------------------");
      
      foreach (char c in characters) {
         bool isPunctuation = Char.IsPunctuation(c);
         Console.WriteLine($"{c}\t\t{isPunctuation}");
      }
   }
}

The output of the above code is −

Character	Is Punctuation
-------------------------
A		False
!		True
?		True
5		False
;		True
[		True
}		True
@		False

Common Use Cases

  • Text parsing − Identifying punctuation marks when processing natural language text.

  • Input validation − Ensuring user input contains or excludes punctuation marks as required.

  • String manipulation − Filtering or replacing punctuation characters in strings.

  • Data cleaning − Removing punctuation from text data for analysis purposes.

Conclusion

The Char.IsPunctuation() method provides an efficient way to determine if a Unicode character is a punctuation mark. It supports all Unicode punctuation categories and is useful for text processing, validation, and data manipulation tasks where punctuation identification is required.

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

323 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements