Skip to content

How do I fetch the position of the first occurrence of a specific value in string

This example demonstrates fetching the position of the first occurrence of a specific value in string.

In the solution shown below, the position of the first occurrence of the substring "testing" is fetched within the string "Worksoft SaaS is a codeless testing tool. Worksoft SaaS is one-stop solution for all your testing needs." using "locateSubstringPosition" command and stored into a variable.

Solution:

# Command Target Value
Fetching the position of first occurrence of the string
1 locateSubstringPosition
Worksoft SaaS is a codeless testing tool. Worksoft SaaS is one-stop solution for all your testing needs.||testing||0
substring_position

Tips, Tricks, Gotchas & Best Practices:

  • The command performs a case-sensitive match while searching for the substring.
  • If the substring is not present within the string, the command returns the value "-1".
  • 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