aqString.Replace Method

Applies to TestComplete 15.68, last modified on October 16, 2024

Description

Use the aqString.Replace method to scan the string specified by the InputString parameter for occurrences of the substring specified by the StringToReplace parameter and substitute them with the value of the SubString parameter.

Declaration

aqString.Replace(InputString, StringToReplace, SubString, CaseSensitive)

InputString [in]    Required    String    
StringToReplace [in]    Required    String    
SubString [in]    Required    String    
CaseSensitive [in]    Optional    Boolean Default value: True   
Result String

Applies To

The method is applied to the following object:

Parameters

The method has the following parameters:

InputString

Specifies the string to be processed.

StringToReplace

Specifies the substring whose occurrences should be replaced.

SubString

Specifies the string to be substituted.

CaseSensitive

Specifies whether the comparison should be case-sensitive or not.

Result Value

The string containing the replaced text.

Example

The code below replaces the "Bob" substring with the "Jack" string.

JavaScript, JScript

function StringReplaceDemo()
{
  var str = "Hi, Bob. Have you seen Bob Robinson?";
  str = aqString.Replace(str, "Bob", "Jack");

  Log.Message(str); // "Hi, Jack. Have you seen Jack Robinson?"
}

Python

def StringReplaceDemo():
  str = "Hi, Bob. Have you seen Bob Robbinson?"
  str = aqString.Replace(str, "Bob", "Jack")

  Log.Message(str) # "Hi, Jack. Have you seen Jack Robinson?"

VBScript

Sub StringReplaceDemo
  Dim str
  str = "Hi, Bob. Have you seen Bob Robinson?"
  str = aqString.Replace(str, "Bob", "Jack")

  Log.Message(str) ' "Hi, Jack. Have you seen Jack Robinson?"
End Sub

DelphiScript

procedure StringReplaceDemo;
var str;
begin
  str := 'Hi, Bob. Have you seen Bob Robinson?';
  str := aqString.Replace(str, 'Bob', 'Jack');

  Log.Message(str); // 'Hi, Jack. Have you seen Jack Robinson?'
end;

C++Script, C#Script

function StringReplaceDemo()
{
  var str = "Hi, Bob. Have you seen Bob Robinson?";
  str = aqString["Replace"](str, "Bob", "Jack");

  Log["Message"](str); // "Hi, Jack. Have you seen Jack Robinson?"
}

See Also

Working With Strings
Insert Method
Remove Method

Highlight search results