Check char type with IsXXX methods in CSharp

Description

The following code shows how to check char type with IsXXX methods.

Example


using System;  /*w w  w . j  av a 2s .  c  om*/
  
public class CharDemo {     
  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.IsDigit(str[i])) 
        Console.Write(" digit"); 
      if(Char.IsLetter(str[i])) 
        Console.Write(" letter"); 
      if(Char.IsLower(str[i])) 
        Console.Write(" lowercase"); 
      if(Char.IsUpper(str[i])) 
        Console.Write(" uppercase"); 
      if(Char.IsSymbol(str[i])) 
        Console.Write(" symbol"); 
      if(Char.IsSeparator(str[i])) 
        Console.Write(" separator"); 
      if(Char.IsWhiteSpace(str[i])) 
        Console.Write(" whitespace"); 
      if(Char.IsPunctuation(str[i])) 
        Console.Write(" punctuation"); 
 
      Console.WriteLine(); 
    } 
 
    Console.WriteLine("Original: " + str); 
 
    // Convert to upper case.    
    string newstr = ""; 
    for(i=0; i < str.Length; i++) 
      newstr += Char.ToUpper(str[i]); 
  
    Console.WriteLine("Uppercased: " + newstr); 
 
  }     
}

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