Char Class

This deals with individual characters
Represents a 16 bit unicode character
With Option Strict On you must convert a String type such as "A" into a Character type by using CChar()
The Char datatype can hold a single Unicode character
The Char class represents a single character.
This class exposes a number of useful shared methods that let you test a single character according to several criteria
All of these methods are overloaded and take either a single Char or a String plus an index in the string


Char.IsLetter(" ") 
Char.IsLetterOrDigit(" ")
Char.IsLower(" ")
Char.IsUpper(" ")
Char.IsPunctuation(" ")
Char.IsSymbol(" ")
Char.IsWhiteSpace(" ")
Char.IsControl(" ")

string mystring; 
mystring = new string(System.Convert.ToChar(90),1);

The Char type represents a Unicode character
If you want to assign a single characeter literal to a Char variable you must use the literal character C to force the string to a Char datatype

Dim myChar As Char 
   myChar = "X"C

Any Char variables are initialised to ""

Explicit conversion

When assigning a literal character to a Char variable you should yse a trailing "c" to make it explicit that the character must be converted to a Char before assignment.

Dim chCharacter As Char 
   chCharacter = "A"c

The following line will cause a complilation error

Dim chCharacter As Char 
   chCharacter = "ABC"c

You cannot assign a string expression to a Char variable, instead you must explicitly ask for a conversion from String to Char using the new CChar conversion function

Dim chCharacter As Char 
   chCharacter = CChar(Mid("Sometext",3,1))

You can also use the Chr function to convert a Unicode code to a character

   chCharacter = Chr(65) 

Char Structure Methods

GetNumericValue -
IsDigit -
IsLetter -
IsUpper -
IsLower -
IsNumber -

© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext