aqString.DeleteListItem Method

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

Description

The aqString.DeleteListItem method deletes an item at the specified index in the string list and returns the resulting list. Items in the 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.DeleteListItem(List, Index)

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. The method does not change the List itself - it returns a copy after the change has been made.

Index

The index of the list item to be removed. 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 removed.

Remarks

The method removes the specified item along with the preceding or following delimiter.

Example

The following script demonstrates how you can use the aqString.DeleteListItem method to remove words from a sentence:

JavaScript, JScript

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

  Log.Message(str);

  str = aqString.DeleteListItem(str, 2);
  Log.Message(str);

  str = aqString.DeleteListItem(str, 6);
  Log.Message(str);

  str = aqString.DeleteListItem(str, 1);
  Log.Message(str);
}

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

Python

def DeleteListItemSample():
  str = "The quick brown fox jumps over the lazy dog"
  aqString.ListSeparator = " "
  Log.Message(str)
  str = aqString.DeleteListItem(str, 2)
  Log.Message(str)
  str = aqString.DeleteListItem(str, 6)
  Log.Message(str)
  str = aqString.DeleteListItem(str, 1)
  Log.Message(str)

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

VBScript

Sub DeleteListItemSample
  Dim str

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

  Log.Message str

  str = aqString.DeleteListItem(str, 2)
  Log.Message str

  str = aqString.DeleteListItem(str, 6)
  Log.Message str

  str = aqString.DeleteListItem(str, 1)
  Log.Message str
End Sub

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

DelphiScript

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

  Log.Message(str);

  str := aqString.DeleteListItem(str, 2);
  Log.Message(str);

  str := aqString.DeleteListItem(str, 6);
  Log.Message(str);

  str := aqString.DeleteListItem(str, 1);
  Log.Message(str);
end;

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

C++Script, C#Script

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

  Log["Message"](str);

  str = aqString["DeleteListItem"](str, 2);
  Log["Message"](str);

  str = aqString["DeleteListItem"](str, 6);
  Log["Message"](str);

  str = aqString["DeleteListItem"](str, 1);
  Log["Message"](str);
}

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

See Also

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

Highlight search results