How do I fetch the position of the last occurrence of a specific value in string
This example demonstrates fetching the position of the last occurrence of a specific value in string.
In the solution shown below, the position of the last 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 "lastIndexOf("<subtring>")" javascript method in "storeEval" command and stored into a variable.
Solution:
# | Command | Target | Value |
---|---|---|---|
Fetching the position of the last occurrence of a specific value in string | |||
1 | storeEval |
function f(){ var string = "Worksoft SaaS is a codeless testing tool. Worksoft SaaS is one-stop solution for all your testing needs."; var substring_position=string.lastIndexOf("testing"); return substring_position; }f(); |
substring_position |
Tips, Tricks, Gotchas & Best Practices:
- 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.