Skip to content

How do I replace all the occurrences of a substring with another substring

This example demonstrates replacing all the occurrences of a substring with another substring.

In the solution shown below, all the occurrences of the substring "worksoft" within the string "worksoft is a codeless testing tool. worksoft is one-stop solution for all your testing needs." are replaced with the substring "Worksoft SaaS" using "replaceSubstringOccurrencesWithinAString" command and stored into a variable.

Solution:

# Command Target Value
Replacing all occurrences of a substring with another substring
1 replaceSubstringOccurrencesWithinAString
worksoft is a codeless testing tool. worksoft is one-stop solution for all your testing needs.||worksoft||Worksoft SaaS replaced_string

Tips, Tricks, Gotchas & Best Practices:

  • The command performs a case-sensitive match while searching for the substring.
  • As a best practice, it is always advisable to define the variable names without any spaces and if you want to differentiate the words, use underscores.


Feedback and Knowledge Base