aqString.ChangeListItem Method

Applies to TestComplete 15.47, last modified on January 20, 2023

Description

The aqString.ChangeListItem method replaces an item at the specified index in the string list and returns the resulting list. Items in the input string list are delimited by the character or substring specified by the aqString.ListSeparator (the default is |). To determine the number of items in the list, use the aqString.GetListLength method.

Declaration

aqString.ChangeListItem(List, NewItem, Index)

List [in]    Required    String    
NewItem [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. The method does not change the List itself - it returns its copy after the replacement has been made.

NewItem

A string to replace the list item at position Index.

Index

The index of the list item to be replaced. 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 copy of the List string with the specified item replaced.

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

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

Example

The following example uses the aqString.ChangeListItem method to replace the first word in a sentence, "The", with the word "A":

JavaScript, JScript

function ChangeListItemSample()
{
  var str = "The quick brown fox jumps over the lazy dog";
  aqString.ListSeparator = " ";

  var str2 = aqString.ChangeListItem(str, "A", 0);
  Log.Message(str2);
}

// Result:
// A quick brown fox jumps over the lazy dog

Python

def ChangeListItemSample():
  str = "The quick brown fox jumps over the lazy dog"
  aqString.ListSeparator = " "
  str2 = aqString.ChangeListItem(str, "A", 0)
  Log.Message(str2)

# Result:
# A quick brown fox jumps over the lazy dog

VBScript

Sub ChangeListItemSample
  Dim str, str2

  str = "The quick brown fox jumps over the lazy dog"
  aqString.ListSeparator = " "

  str2 = aqString.ChangeListItem(str, "A", 0)
  Log.Message str2
End Sub

' Result:
' A quick brown fox jumps over the lazy dog

DelphiScript

procedure ChangeListItemSample;
var str, str2;
begin
  str := 'The quick brown fox jumps over the lazy dog';
  aqString.ListSeparator := ' ';

  str2 := aqString.ChangeListItem(str, 'A', 0);
  Log.Message(str2);
end;

// Result:
// A quick brown fox jumps over the lazy dog

C++Script, C#Script

function ChangeListItemSample()
{
  var str = "The quick brown fox jumps over the lazy dog";
  aqString["ListSeparator"] = " ";

  var str2 = aqString["ChangeListItem"](str, "A", 0);
  Log["Message"](str2);
}

// Result:
// A quick brown fox jumps over the lazy dog

See Also

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

Highlight search results