Chr Function

Applies to TestComplete 15.47, last modified on January 20, 2023

The Chr function returns a character with the specified ASCII code.

Declaration

Chr(Value) Parameters
Value [in] Required Integer
Result     String  

Description

Returns a character that is associated with the ASCII code specified by the Value parameter.

Parameters

The function has one parameter:

Value

A number between 0 and 255 that specifies the ASCII code of the desired character. Codes from 0 through 31 correspond to non-printable characters.

Return Value

The character associated with the specified ASCII code.

Example

The following example demonstrates how you can use the Chr function to obtain characters by their ASCII codes.

JavaScript, JScript

function Test()
{
  Log.Message( Chr(65) );  // A
  Log.Message( Chr(90) );  // Z
  Log.Message( Chr(97) );  // a
  Log.Message( Chr(122));  // z
  Log.Message( Chr(48) );  // 0
  Log.Message( Chr(57) );  // 9
  Log.Message( Chr(42) );  // *
  Log.Message( Chr(64) );  // @
}

Python

def Test():
  Log.Message( Chr(65) );  # A
  Log.Message( Chr(90) );  # Z
  Log.Message( Chr(97) );  # a
  Log.Message( Chr(122));  # z
  Log.Message( Chr(48) );  # 0
  Log.Message( Chr(57) );  # 9
  Log.Message( Chr(42) );  # *
  Log.Message( Chr(64) );  # @

VBScript

Sub Test
  Log.Message Chr(65)  ' A
  Log.Message Chr(90)  ' Z
  Log.Message Chr(97)  ' a
  Log.Message Chr(122) ' z
  Log.Message Chr(48)  ' 0
  Log.Message Chr(57)  ' 9
  Log.Message Chr(42)  ' *
  Log.Message Chr(64)  ' @
End Sub

DelphiScript

procedure Test;
begin
  Log.Message( Chr(65) );  // A
  Log.Message( Chr(90) );  // Z
  Log.Message( Chr(97) );  // a
  Log.Message( Chr(122));  // z
  Log.Message( Chr(48) );  // 0
  Log.Message( Chr(57) );  // 9
  Log.Message( Chr(42) );  // *
  Log.Message( Chr(64) );  // @
end;

C++Script, C#Script

function Test()
{
  Log["Message"]( Chr(65) );  // A
  Log["Message"]( Chr(90) );  // Z
  Log["Message"]( Chr(97) );  // a
  Log["Message"]( Chr(122));  // z
  Log["Message"]( Chr(48) );  // 0
  Log["Message"]( Chr(57) );  // 9
  Log["Message"]( Chr(42) );  // *
  Log["Message"]( Chr(64) );  // @
}

Remarks

In JScript, C++Script and C#Script you can also use the native String.fromCharCode method to get a character associated with a specific ASCII or Unicode code. In Python, you can use the native chr method to get a character by its ASCII code. In VBScript, you can use ChrW to get a character by its Unicode code.

To perform the opposite task, that is, to get the ASCII code of a character, use the following functions:

  • Asc or AscW - in VBScript

  • strObj.charCodeAt - in JavaScript, JScript, C++Script and C#Script

  • ord - in Python

  • Ord - in DelphiScript

For more information and for examples of performing various string operations, see Working With Strings.

See Also

Working With Strings

Highlight search results