Home
VB.NET
Chr Function: Get Char From Integer
Updated Mar 28, 2022
Dot Net Perls
Chr. 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.
Val
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.
Integer
Char
Example. Here the first variable "c" is assigned to the character "x". The second variable "i" is set to the ASCII value underlying the "x".
And The "h" variable (the third one) shows how to convert an integer back into a character.
Important The program gets a 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 Module
x 120 x
Program details. You can see that the ASCII representation for "x" is equal to 120. Then, the character representation (Chr) of 120 is equal to "x".
So The Asc and Chr functions can be used to reverse each other's effects on a value.
Warning The Asc and Chr functions are not available in the C# language. They are only useful in VB.NET programs.
Summary. 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.
Dot Net Perls is a collection of pages with code examples, which are updated to stay current. Programming is an art, and it can be learned from examples.
Donate to this site to help offset the costs of running the server. Sites like this will cease to exist if there is no financial support for them.
Sam Allen is passionate about computer languages, and he maintains 100% of the material available on this website. He hopes it makes the world a nicer place.
This page was last updated on Mar 28, 2022 (edit link).
Home
Changes
© 2007-2025 Sam Allen