Utilities.StringReplace Method

Applies to TestComplete 15.10, last modified on December 01, 2021
This method is obsolete. See the Remarks section below.


The Utilities.StringReplace method scans the given string (Str), replaces occurrences of the substring specified by the OldPattern parameter with the substring specified by the NewPattern parameter and returns the resulting string.


Utilities.StringReplace(Str, OldPattern, NewPattern, Flags)

Str [in]    Required    String    
OldPattern [in]    Required    String    
NewPattern [in]    Required    String    
Flags [in]    Required    Byte    
Result String

Applies To

The method is applied to the following object:


The method has the following parameters:


Specifies the string whose substring should be replaced.


Specifies the substring that should be replaced with the NewPattern in the given string.


Specifies the substring that will replace the OldPattern.


The Flags parameter controls how occurrences of OldPattern are located and replaced. You can use any of the following values individually or combine them using the logical (bitwise) OR operator.

Value Description
1 Replaces all occurrences. If this flag is not used, only the first occurrence of the target substring is replaced.
2 Matches occurrences of the substring case-insensitively. If this flag is not used, only case-sensitive matches are considered.

You can also use the rfReplaceAll (0) and rfIgnoreCase (1) constants defined in the Utilities object to specify the desired value of the Flags parameter. Note that in this case you should combine these constants into a set value using the MkSet function before passing them to StringReplace. For instance:

JavaScript, JScript

function TestProc()
  var st, s;
  st = MkSet (Utilities.rfReplaceAll, Utilities.rfIgnoreCase);
  s = Utilities.StringReplace ("AbaA", "B", "C", st);


def TestProc():
  st = MkSet(Utilities.rfReplaceAll, Utilities.rfIgnoreCase)
  s = Utilities.StringReplace ("AbaA", "B", "C", st)


Sub TestProc
  Dim st, s
  st = MkSet (Utilities.rfReplaceAll, Utilities.rfIgnoreCase)
  s = Utilities.StringReplace ("AbaA", "B", "C", st)
End Sub


procedure TestProc;
  st, s;
  st := MkSet (Utilities.rfReplaceAll, Utilities.rfIgnoreCase);
  s := Utilities.StringReplace ('AbaA', 'B', 'C', st);

C++Script, C#Script

function TestProc()
  var st, s;
  st = MkSet (Utilities["rfReplaceAll"], Utilities["rfIgnoreCase"]);
  s = Utilities["StringReplace"]("AbaA", "B", "C", st);

Even if you decide to use only one of these constants, you should add it to the set value.

Result Value

The given string with the OldPattern substring replaced with the string specified by the NewPattern parameter.


This method is obsolete. It is supported for backward compatibility only. To replace text within a string, use the aqString.Replace method.

See Also

Replace Method
Quote Method
Unquote Method
Find Method
MkSet Function

Highlight search results