aqString.GetChar Method

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

Description

Use the GetChar method to get the character located at the specified position within a string.

Declaration

aqString.GetChar(InputString, Position)

InputString [in]    Required    String    
Position [in]    Required    Integer    
Result Character

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

InputString

A string containing the desired character.

Position

The zero-based index of the character within InputString. The first character is at position 0, the second is at position 1, and so on. The position of the last character is equal to the string length minus 1.

Result Value

The character located at the specified position in the string.

Example

The code below splits the specified string into characters and posts them to the test log.

JavaScript, JScript

function StringByLetter()
{
  
  // Specifies the string
  var aString = "Per aspera ad astra";
  Log.Message("The string is : " + aString);
  Log.Message("And now, this text letter by letter using GetChar method:");
  
  // Posts the specified string letter by letter to the test log
  for (var i = 0; i < aqString.GetLength(aString); i++)
    Log.Message(aqString.GetChar(aString, i));
  
}

Python

def StringByLetter():
  # Specifies the string
  aString = "Per aspera ad astra"
  Log.Message("The string is : " + aString)
  Log.Message("And now, this text letter by letter using GetChar method:")
  # Posts the specified string letter by letter to the test log
  for i in range(0, aqString.GetLength(aString)):
    Log.Message(aqString.GetChar(aString, i))

VBScript

Sub StringByLetter
  Dim aString, i
  
  ' Specifies the string
  aString = "Per aspera ad astra"
  Log.Message("The string is : " & aString)
  Log.Message("And now, this text letter by letter using GetChar method:")
  
  ' Posts the specified string letter by letter to the test log
  For i = 0 To aqString.GetLength(aString)-1
    Log.Message(aqString.GetChar(aString, i))
  Next
  
End Sub

DelphiScript

function StringByLetter;
var aString, i;
begin

  // Specifies the string
  aString := 'Per aspera ad astra';
  Log.Message('The string is : ' + aString);
  Log.Message('And now, this text letter by letter using GetChar method:');
  
  // Posts the specified string letter by letter to the test log
  for i := 0 to aqString.GetLength(aString)-1 do
    Log.Message(aqString.GetChar(aString, i));
  
end;

C++Script, C#Script

function StringByLetter()
{
  
  // Specifies the string
  var aString = "Per aspera ad astra";
  Log["Message"]("The string is : " + aString);
  Log["Message"]("And now, this text letter by letter using GetChar method:");
  
  // Posts the specified string letter by letter to the test log
  for (var i = 0; i < aqString["GetLength"](aString); i++)
    Log["Message"]( aqString["GetChar"](aString, i) );
  
}

See Also

Working With Strings
GetLength Method
SubString Method
Remove Method
Replace Method

Highlight search results