We are building a new experience for our SmartBear Community.
This site is now read-only. You can still browse and search as usual. Learn More

Forum Discussion

Naveenks's avatar
Naveenks
Contributor
7 years ago
Solved

Capturing dynamic string character

Hi,

 

I have to capture "There are 138 records in table" and then i have to extract only 138 using java script.

Please help me in creating the script.

Regards,

Naveen....

  • var a = "There are 138 records in table"
    
    function Test()
    {
      Log.Message(getCount(a));
    }
    
    function getCount(str)
    {
      str = str.replace("There are ","")
      str = str.replace("There is ","")
      str = str.replace(" records in table","")
      str = str.replace(" record in table","")
      return VarToInt(str)
    }
  • Bobik, interesting approach!

     

    Naveenks, in addition to Bobik's suggestion, please take a look at regular expressions - this is a powerful instrument to work with strings. You can find more information here:

     https://support.smartbear.com/testcomplete/docs/scripting/regular-expressions.html

2 Replies

  • Bobik's avatar
    Bobik
    Frequent Contributor
    var a = "There are 138 records in table"
    
    function Test()
    {
      Log.Message(getCount(a));
    }
    
    function getCount(str)
    {
      str = str.replace("There are ","")
      str = str.replace("There is ","")
      str = str.replace(" records in table","")
      str = str.replace(" record in table","")
      return VarToInt(str)
    }
    • Bobik, interesting approach!

       

      Naveenks, in addition to Bobik's suggestion, please take a look at regular expressions - this is a powerful instrument to work with strings. You can find more information here:

       https://support.smartbear.com/testcomplete/docs/scripting/regular-expressions.html