aqString.GetListLength Method

Applies to TestComplete 14.20, last modified on September 11, 2019

Description

The aqString.GetListLength method returns the number of items in the List string that are delimited by the aqString.ListSeparator character or string (default is |). Use this method when you need to enumerate items in the List. To get an individual item, use the aqString.GetListItem method.

Declaration

aqString.GetListLength(List)

List [in]    Required    String    
Result Integer

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

List

A string containing items delimited by the character or string specified by the aqString.ListSeparator property.

Result Value

The number of items in the List that are delimited by the aqString.ListSeparator character or string. If List does not contain any instance of aqString.ListSeparator, the method returns 1. If List is an empty string, the method also returns 1 (see Remarks).

Remarks

If the List contains two adjacent delimiters or if the delimiter occurs at the beginning or end of the List, the corresponding list item is considered empty. Empty items are also counted.

An empty string is considered as consisting of one empty item.

Example

The following table lists some sample input strings for the aqString.GetListLength method, the corresponding item separators and the resulting item count:

List aqString.ListSeparator Item Count
"Hello, world!" "," 2
"Hello, world!" "." 1
"Hello, world!" "o" 3
"4;;8;;16" ";" 5
";4;8;16;" ";" 5
"-" "-" 2
"" (empty string) any 1 (see Remarks)

The script below demonstrates how you can use the aqString.GetListLength method to count the number of items in a string list:

JavaScript, JScript

function GetListLengthSample()
{
  var str = "This is a test.";
  aqString.ListSeparator = " ";

  Log.Message(aqString.GetListLength(str));
}

Python

def GetListLengthSample():
  str = "This is a test."
  aqString.ListSeparator = " "
  Log.Message(aqString.GetListLength(str))

VBScript

Sub GetListLengthSample
  Dim str

  str = "This is a test."
  aqString.ListSeparator = " "

  Log.Message aqString.GetListLength(str)
End Sub

DelphiScript

procedure GetListLengthSample;
var str;
begin
  str := 'This is a test.';
  aqString.ListSeparator := ' ';

  Log.Message(aqString.GetListLength(str));
end;

C++Script, C#Script

function GetListLengthSample()
{
  var str = "This is a test.";
  aqString["ListSeparator"] = " ";

  Log["Message"](aqString["GetListLength"](str));
}

See Also

Working With Strings
aqString.AddListItem Method
aqString.ChangeListItem Method
aqString.DeleteListItem Method
aqString.GetListItem Method
aqString.ListSeparator Property

Highlight search results