In VB.NET programs Chr()
deals with Integers and Chars. Often we must convert Integers into Chars. And with Chr()
we can perform this conversion easily.
By using the Chr function, you can take an Integer that represents a specific character and then acquire the actual Char
value. An understanding of ASCII codes is helpful in learning about Chr.
Here the first variable "c" is assigned to the character "x". The second variable "i" is set to the ASCII value underlying the "x".
Char
from an Integer. This is useful for calling methods that require Char
.Module Module1 Sub Main() Dim c As Char = "x"c ' Input character. Dim i As Integer = Asc(c) ' Convert to ascii integer. Dim h As Char = Chr(i) ' Convert ascii integer to char. Console.WriteLine(c) Console.WriteLine(i) Console.WriteLine(h) End Sub End Modulex 120 x
Program
detailsYou can see that the ASCII representation for "x" is equal to 120. Then, the character representation (Chr) of 120 is equal to "x".
Here, we showed how you can use Asc and Chr to manipulate ASCII integers for characters in the VB.NET language. In some algorithms, the Integer representation of a Char
is more useful.