cancel
Showing results for 
Search instead for 
Did you mean: 

Extracting A Section of Text From a String

SOLVED
RichBopp
Contributor

Extracting A Section of Text From a String

Looking for a Keyword Test Solution:  Our website displays the customer's Order Number as part of a string - i.e. "Order # 52846700" 

I've watched the 'How To Get a Value From on Screen and Store it for Later Use' video - and that would be fine if the order number was displayed in the field by itself - it is not.  

RichBopp_0-1618610385457.png

 

Is there a way to extract just the Order Number - Either from the screen into the Variable, or from the Variable itself?

1 ACCEPTED SOLUTION

Accepted Solutions
Marsha_R
Community Hero

Re: Extracting A Section of Text From a String

Here you go - you'll need a Code Expression to do it from a keyword test

 

Marsha_R_0-1618848777560.png

 

View solution in original post

8 REPLIES 8
Marsha_R
Community Hero

Re: Extracting A Section of Text From a String

Extract the value with Set Variable Value - you'll have a choice in there to pick Object Property, which will then give you the Object Spy to get your object from the screen and you can pick the field in there.

 

Marsha_R_0-1618612016707.png

 

With your string "Order # 52846770", if you know the first 8 characters are always stuff you don't need, then you can do something like aqString.Remove

Marsha_R_1-1618612934736.png

My text was "Running applications" and I ended up with "applications"

 

Marsha_R_2-1618612987194.png

 

There are other methods like Substring that could be useful too.

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqstring/index.html

 

Play around with them a little to see how the string manipulation works.

 

 

 

 

 

 

RichBopp
Contributor

Re: Extracting A Section of Text From a String

Well - using the Video I mentioned, I'm able to get the full object text and write it out to the Log (i.e. ORDER # 52846772), but for the life of me when I try to do the 'aqString.Remove' option you suggest - I can't find it.

 

Guessing it is buried somewhere in all of the options - or I'm just blind.

 

Where is it located?  Could you provide a screenshot, please? 

Marsha_R
Community Hero

Re: Extracting A Section of Text From a String

Here you go - you'll need a Code Expression to do it from a keyword test

 

Marsha_R_0-1618848777560.png

 

View solution in original post

RichBopp
Contributor

Re: Extracting A Section of Text From a String

Excellent!!  That worked.

 

Now - The million dollar question - How do I take that Order #, and plug it into a Data Base Query?  

 

We have many test cases that would find value in such a thing.  Example, when a customer located in a specific ZIP code places an order, they should be serviced by the closest distribution center.   So say customer in ZIP '60085' should be serviced by 'I6' - 

 

RichBopp_1-1618865148473.png

So - How do we plug the Order Number into the Custom Query (where WBORDN = 52846802)? 

 

Or is there another option available that will get us to the same place?

ebarbera
Staff

Re: Extracting A Section of Text From a String

Hi @RichBopp 

 

Not sure if this helps - but it seems like you should be able to do this inside a function. 

 

https://support.smartbear.com/testcomplete/docs/testing-with/working-with-external-data-sources/data...

 

In a function you should be able to reference your project variable. 

 

 

 

 

Marsha_R
Community Hero

Re: Extracting A Section of Text From a String

RichBopp
Contributor

Re: Extracting A Section of Text From a String

Gang - Marsha_R was able to provide a solution to my original question about extracting specific text from a string.  Thank you very much - this will be handy.

 

But my follow up 'million dollar' question - as to how to take that text (in my case an Order Number) and then insert that number into a Custom SQL query - can not be done with our current functionality.

 

So - I've put in a Feature Request.  Maybe some day, my friends.  Maybe some day.

AlexKaras
Community Hero

Re: Extracting A Section of Text From a String

Hi,

 

can not be done with our current functionality.

Can you clarify what exactly cannot be done?

Obtained value can be stored to the variable. Later, when you compose query expression this value can be utilized either directly or as a parameter. So I am not sure what you have problem with. (Unless you are trying to do everything using only keyword operations and do not use code.)

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
New Here?
Join us and watch the welcome video:
Announcements