Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

Strings.Chr Method

Returns the character associated with the specified character code.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
'Declaration
Public Shared Function Chr ( _
	CharCode As Integer _
) As Char
'Usage
Dim CharCode As Integer 
Dim returnValue As Char 

returnValue = Strings.Chr(CharCode)

Parameters

CharCode
Type: System.Int32

Required. An Integer expression representing the code point, or character code, for the character. If CharCode is outside the valid range, an ArgumentException error occurs. The valid range for Chr is 0 through 255, and the valid range for ChrW is -32768 through 65535.

Return Value

Type: System.Char
Returns the character associated with the specified character code.

For more detailed information, see the Visual Basic topic Chr, ChrW Functions.

The asymmetric range accepted for CharCode compensates for the storage differences between the Short Data Type (Visual Basic) and the Integer Data Type (Visual Basic). For example, -29183 is a Short but +36353 is an Integer. This also facilitates compatibility with Visual Basic 6.0.

Chr uses the Encoding class in the System.Text namespace to determine if the current thread is using a single-byte character set (SBCS) or a double-byte character set (DBCS). It then takes CharCode as a code point in the appropriate set. The range can be 0 through 255 for SBCS characters and -32768 through 65535 for DBCS characters.

The returned value depends on the code page for the current thread, which is contained in the ANSICodePage property of the TextInfo class in the System.Globalization namespace. You can obtain ANSICodePage by specifying System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage.

ChrW takes CharCode as a Unicode code point. The range is independent of the culture and code page settings for the current thread. Values from -32768 through -1 are treated the same as values in the range +32768 through +65535.

Numbers from 0 through 31 are the same as standard nonprintable ASCII codes. For example, Chr(10) returns a line feed character.

NoteNote:

The ChrB function in earlier versions of Visual Basic returns a single byte. It is used primarily for converting strings in double-byte character set (DBCS) applications. All strings in Visual Basic and the .NET Framework are in Unicode, and ChrB is no longer supported.

The following example uses the Chr function to return the character associated with the specified character code.

Dim associatedChar As Char 
' Returns "A".
associatedChar = Chr(65)
' Returns "a".
associatedChar = Chr(97)
' Returns ">".
associatedChar = Chr(62)
' Returns "%".
associatedChar = Chr(37)

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.