aqString.GetListItem Method

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

Description

The aqString.GetListItem method returns an item at the specified index in the string list where items are delimited by the aqString.ListSeparator. To get the total number of items in a string list, use aqString.GetListLength. The aqString.GetListItem method is usually used along with aqString.GetListLength to enumerate list items.

Declaration

aqString.GetListItem(ListIndex)

List [in]    Required    String    
Index [in]    Required    Integer    
Result String

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

List

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

Index

The index of the list item to retrieve. The index is zero-based: 0 means the first item; 1 - the second and so forth. Index of the last item is aqString.GetListLength(List)-1.

Result Value

A string holding the list item as the specified index.

Remarks

Delimiter characters are not included in the items.

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 an empty string.

If List is an empty string, it is considered as consisting of one empty string item.

Example

The following table lists some sample input strings for the aqString.GetListItem method, item separators and the list items and their indices:

List aqString.ListSeparator Items
"Hello, world!" "," 0: "Hello"
1: " world!"
"Hello, world!" "." 0: "Hello, world!"
"4;8;16" ";" 0: "4"
1: "8"
2: "16"
"4;;8;;16" ";" 0: "4"
1: "" (empty string)
2: "8"
3: "" (empty string)
5: "16"
";4;8;16;" ";" 0: "" (empty string)
1: "4"
2: "8"
3: "16"
4: "" (empty string)
"-" "-" 0: "" (empty string)
1: "" (empty string)
"" (empty string) any 0: "" (empty string)

The script example below demonstrates how you can enumerate delimited items in a list:

JavaScript, JScript

function GetListItemSample()
{
  var str = "0;1;1;2;3;5;8;13;21;34";
  aqString.ListSeparator = ";";

  for (var i = 0; i < aqString.GetListLength(str); i++)
    Log.Message(aqString.GetListItem(str, i));
}

Python

def GetListItemSample():
  str = "0;1;1;2;3;5;8;13;21;34"
  aqString.ListSeparator = ";"
  for i in range(0, aqString.GetListLength(str)):
    Log.Message(aqString.GetListItem(str, i))

VBScript

Sub GetListItemSample
  Dim str, i

  str = "0;1;1;2;3;5;8;13;21;34"
  aqString.ListSeparator = ";"

  For i = 0 to aqString.GetListLength(str) - 1
    Log.Message aqString.GetListItem(str, i)
  Next
End Sub

DelphiScript

procedure GetListItemSample;
var str, i;
begin
  str := '0;1;1;2;3;5;8;13;21;34';
  aqString.ListSeparator := ';';

  for i := 0 to aqString.GetListLength(str) - 1 do
    Log.Message(aqString.GetListItem(str, i));
end;

C++Script, C#Script

function GetListItemSample()
{
  var str = "0;1;1;2;3;5;8;13;21;34";
  aqString["ListSeparator"] = ";";

  for (var i = 0; i < aqString["GetListLength"](str); i++)
    Log["Message"](aqString["GetListItem"](str, i));
}

See Also

Working With Strings
AddListItem Method
ChangeListItem Method
DeleteListItem Method
GetListLength Method
ListSeparator Property

Highlight search results