cancel
Showing results for 
Search instead for 
Did you mean: 

Capturing dynamic string character

SOLVED
Highlighted
Contributor

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....

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Contributor

Re: Capturing dynamic string character

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)
}

View solution in original post

Highlighted
Community Manager

Re: Capturing dynamic string character

@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

---------
Tanya Gorbunova
SmartBear Community Manager

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today

View solution in original post

2 REPLIES 2
Highlighted
Contributor

Re: Capturing dynamic string character

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)
}

View solution in original post

Highlighted
Community Manager

Re: Capturing dynamic string character

@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

---------
Tanya Gorbunova
SmartBear Community Manager

Learn SmartBear products in a fun and easy way and prove your knowledge!
>>Participate in the TechCorner Challenge today

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!

Challenge Status

Changing options from outside of TestComplete

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!

Comparing content of HTML table with Excel file data

Participate!

Compare HTML table with Excel file and correct data in the file

Participate!
Top Kudoed Authors