aqString.Trim Method

Applies to TestComplete 14.0, last modified on January 23, 2019

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(InputStringSpace)

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
aqString.Find Method
aqString.Quote Method
aqString.Unquote Method

Highlight search results