aqString.Trim Method

Applies to TestComplete 15.63, last modified on April 10, 2024

Description

Use the Trim method to remove spaces (either leading or trailing, or both) and control characters (either leading or trailing, or both) from the string specified by the InputString parameter.

Declaration

aqString.Trim(InputString, Space)

InputString [in]    Required    String    
Space [in]    Optional    Integer Default value: stAll   
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 spaces and control characters should be removed.

Space

Specifies which spaces to remove. You can use an integer or the following constants:

Constant Value Description
stLeading 1 Leading spaces will be trimmed.
stTrailing 2 Trailing spaces will be trimmed.
stAll 3 Both leading and trailing spaces will be trimmed.

Result Value

The given string without spaces and control characters.

Example

The code below removes spaces from the " Hello " string.

JavaScript, JScript

function TrimDemo()
{
  var str = " Hello ";

  Log.Message("'" + aqString.Trim(str, aqString.stLeading) + "'"); // Posts 'Hello '
  Log.Message("'" + aqString.Trim(str, aqString.stTrailing) + "'"); // Posts ' Hello'
  Log.Message("'" + aqString.Trim(str, aqString.stAll) + "'"); // Posts 'Hello'
}

Python

def TrimDemo():
  str = " Hello "
  Log.Message("'" + aqString.Trim(str, aqString.stLeading) + "'") # Posts 'Hello '
  Log.Message("'" + aqString.Trim(str, aqString.stTrailing) + "'") # Posts ' Hello' 
  Log.Message("'" + aqString.Trim(str, aqString.stAll) + "'") # Posts 'Hello'

VBScript

Sub TrimDemo
  Dim str
  str = " Hello "

  Log.Message("'" & aqString.Trim(str, aqString.stLeading) & "'") ' Posts 'Hello '
  Log.Message("'" & aqString.Trim(str, aqString.stTrailing) & "'") ' Posts ' Hello'
  Log.Message("'" & aqString.Trim(str, aqString.stAll) & "'") ' Posts 'Hello'

End Sub

DelphiScript

function TrimDemo;
var str;
begin
  str := ' Hello ';

  Log.Message('''' + aqString.Trim(str, aqString.stLeading) + ''''); // Posts 'Hello '
  Log.Message('''' + aqString.Trim(str, aqString.stTrailing) + ''''); // Posts ' Hello'
  Log.Message('''' + aqString.Trim(str, aqString.stAll) + ''''); // Posts 'Hello'
end;

C++Script, C#Script

function TrimDemo()
{
  var str = " Hello ";

  Log["Message"]( "'" + aqString["Trim"]( str, aqString["stLeading"] ) + "'" ); // Posts 'Hello '
  Log["Message"]( "'" + aqString["Trim"]( str, aqString["stTrailing"] ) + "'" ); // Posts ' Hello'
  Log["Message"]( "'" + aqString["Trim"]( str, aqString["stAll"] ) + "'" ); // Posts 'Hello'
}

See Also

Working With Strings
Find Method
Quote Method
Unquote Method

Highlight search results