Check if a character is a Punctuation in CSharp

Description

The following code shows how to check if a character is a Punctuation.

Example


using System;  // w ww  .j a v  a2 s. c  o  m
  
class MainClass {     
  public static void Main() {     
    string str = "This is a test. $23"; 
    int i; 
 
    for(i=0; i < str.Length; i++) { 
      Console.Write(str[i] + " is"); 
      if(Char.IsPunctuation(str[i])) 
        Console.Write(" punctuation"); 
 
      Console.WriteLine(); 
    } 
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var