C# | Char.IsPunctuation() Method - GeeksforGeeks

31 Jan, 2019
In C#, Char.IsPunctuation() is a System.Char struct method which is used to check whether an Unicode character can be categorized as a punctuation mark or not. This method can be overloaded by passing different type and number of arguments to it.
Char.IsPunctuation(Char) MethodChar.IsPunctuation(String, Int32) Method
Char.IsPunctuation(Char) Method
Char.IsPunctuation(String, Int32) Method
This method is used to check whether the specified Unicode character matches with any punctuation mark or not. If it matches then it returns True otherwise return False.
Syntax:
public static bool IsPunctuation(char ch);

Parameter:
ch: It is the required Unicode character of System.char type which is to be compared.
Return Type: This method returns True, if it successfully matches any punctuation mark, otherwise returns False. The return type of this method is System.Boolean.
Example:
// C# program to illustrate the// Char.IsPunctuation(Char) Methodusing System;  class GFG {      // Main Method    static public void Main()    {          // Declaration of data type        bool result;          // checking if dot(.)        // is a punctuation mark        char ch1 = '.';        result = Char.IsPunctuation(ch1);        Console.WriteLine(result);          // checking if semi-colon( ; )        // is a punctuation mark        char ch2 = ';';        result = Char.IsPunctuation(ch2);        Console.WriteLine(result);          // checking if comma (, )        // is a punctuation mark        char ch3 = ', ';        result = Char.IsPunctuation(ch3);        Console.WriteLine(result);          // checking if 'g' is        // a punctuation mark        char ch5 = 'g';        result = Char.IsPunctuation(ch5);        Console.WriteLine(result);    }}
True
True
True
False

This method is used to check whether the specified string at specified position matches with any punctuation mark or not. If it matches then it returns True otherwise returns False.
Syntax:
public static bool IsPunctuation(string str, int index);

Parameters:
str: It is the required string of System.String type which is to be compared.index: It is the position of character in string which is to be compared and type of this parameter is System.Int32.
Return Type: The method returns True, if it successfully matches punctuation mark at the specified index in the specified string, otherwise returns False. The return type of this method is System.Boolean.
Exceptions:
If the value of str is null then this method will give ArgumentNullException
If the index is less than zero or greater than the last position in str then this method will give ArgumentOutOfRangeException.
Example:
// C# program to illustrate the// Char.IsPunctuation(String, Int32) Methodusing System;  class GFG {      // Main Method    static public void Main()    {          // Declaration of data type        bool result;          // checking for punctuation        // in a string at specific location        string str1 = "GeeksforGeeks";        result = Char.IsPunctuation(str1, 2);        Console.WriteLine(result);          // checking for punctuation        // in a string at specific location        string str2 = "www.geeksforgeeks.org";        result = Char.IsPunctuation(str2, 3);        Console.WriteLine(result);    }}
False
True

Reference: https://docs.microsoft.com/en-us/dotnet/api/system.char.ispunctuation?view=netframework-4.7.2
CSharp-Char-Struct
CSharp-method
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between Abstract Class and Interface in C#
C# | How to check whether a List contains a specified element
C# | IsNullOrEmpty() Method
String.Split() Method in C# with Examples
C# | Method Overriding
C# Dictionary with examples
C# | Arrays of Strings
Difference between Ref and Out keywords in C#
C# | Delegates
Destructors in C#