aqString.SubString Method

Applies to TestComplete 14.72, last modified on April 22, 2021

Description

Use the SubString method to obtain a text fragment starting from the specified position and having the specified length.

Declaration

aqString.SubString(InputStringStartPositionLength)

InputString [in]    Required    String    
StartPosition [in]    Required    Integer    
Length [in]    Required    Integer    
Result String

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

InputString

Specifies the string from which a substring will be retrieved.

StartPosition

A zero-based position of the character where the desired substring starts.

Length

The number of characters in the substring.

Result Value

The retrieved substring.

Example

The code below gets different substrings from the specified string via the SubString method.

JavaScript, JScript

function GetSubString()
{
  var Str = "123456789";
  
  // Uses the SubString method
  Log.Message( aqString.SubString(Str, 0, 4) ); // Posts "1234"
  Log.Message( aqString.SubString(Str, 3, 5) ); // Posts "45678"
  Log.Message( aqString.SubString(Str, 6, 20) ); // Posts "789"
  Log.Message( aqString.SubString(Str, 2, 0) ); // Posts ""
}

Python

def GetSubString():
  Str = "123456789"
  # Uses the SubString method 
  Log.Message(aqString.SubString(Str, 0, 4)) # Posts "1234"
  Log.Message(aqString.SubString(Str, 3, 5)) # Posts "45678"
  Log.Message(aqString.SubString(Str, 6, 20)) # Posts "789"
  Log.Message(aqString.SubString(Str, 2, 0)) # Posts ""

VBScript

Sub GetSubString

  Str = "123456789"
  
  ' Uses the SubString method
  Log.Message( aqString.SubString(Str, 0, 4) ) ' Posts "1234"
  Log.Message( aqString.SubString(Str, 3, 5) ) ' Posts "45678"
  Log.Message( aqString.SubString(Str, 6, 20) ) ' Posts "789"
  Log.Message( aqString.SubString(Str, 2, 0) ) ' Posts ""
  
End Sub

DelphiScript

function GetSubString;
var Str;
begin
  Str := '123456789';
  
  // Uses the SubString method
  Log.Message( aqString.SubString(Str, 0, 4) ); // Posts "1234"
  Log.Message( aqString.SubString(Str, 3, 5) ); // Posts "45678"
  Log.Message( aqString.SubString(Str, 6, 20) ); // Posts "789"
  Log.Message( aqString.SubString(Str, 2, 0) ); // Posts ""
end;

C++Script, C#Script

function GetSubString()
{
  var Str = "123456789";
  
  // Uses the SubString method
  Log["Message"]( aqString["SubString"]( Str, 0, 4 ) ); // Posts "1234"
  Log["Message"]( aqString["SubString"]( Str, 3, 5 ) ); // Posts "45678"
  Log["Message"]( aqString["SubString"]( Str, 6, 20 ) ); // Posts "789"
  Log["Message"]( aqString["SubString"]( Str, 2, 0 ) ); // Posts ""
}

See Also

Working With Strings
Insert Method
Remove Method
Replace Method
GetChar Method

Highlight search results