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.
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.
public static bool IsPunctuation(char ch);
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.
True True True False
Char.IsPunctuation(String, Int32) Method
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.
public static bool IsPunctuation(string str, int index);
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.
- 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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.