Updated on 2026-08-11 GMT+08:00

Replacing a String

Function Name

$strReplace(String str, String old, String replace, boolean isRegular)

Parameter Description

  • str: Accepts a string, local parameter, environment parameter, or built-in function.
  • old: Accepts a string, local parameter, environment parameter, or built-in function.
  • replace: Accepts a string, local parameter, environment parameter, or built-in function.
  • replace: Accepts true or false to indicate whether to use a regular expression for replacement. If it is set to true, the old parameter accepts regex.

Function Description

Replaces a URL request parameter value or part of the value and assigns the value to the str parameter.

Application Scenarios

This function can be used in the following parts of an API automation test case. (Do not use the function for environment parameters. Otherwise, what is input will be output.)

  • Request URL
  • Request header
  • Request body
  • Checkpoint property
  • if condition
  • for loop interrupt condition

Example

  • Request URL

As shown in the URL request in Figure 2, the string replacement function is used in the request body to replace the value of the environment parameter New_Variable_2 and assign the new value to keyword.

Figure 1 Old environment parameter value
Figure 2 Replacing the environment parameter value

After saving and running the script, you can view the details in the execution history.