Skip to content

How do I extract the part of a string from a large string or a sentence

This example demonstrates extracting the part of a string from a large string or a sentence.

In the solution shown below, the substring "Worksoft SaaS" is extracted from the string "Worksoft SaaS is a codeless testing tool" using "substr(<first index of substring,last index of the substring+1>)" javascript method in "storeEval" command and stored into a variable.

Solution:

# Command Target Value
Extracting part of a string from the entire string
1 storeEval function f(){ var string = "Worksoft SaaS is a codeless testing tool"; var substring=string.substr(0,6); return substring; }f();  substring

Tips, Tricks, Gotchas & Best Practices:

  • You can also use slice() method in place of substr() method for extracting the part of a string from the entire string.
  • In Javascript the index values of a string starts from "0".
  • 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