Forum Discussion

RichBopp's avatar
RichBopp
Contributor
3 years ago
Solved

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.  

 

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

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

     

     

8 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    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.

     

     

    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

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

     

     

    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's avatar
      RichBopp
      Contributor

      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's avatar
        Marsha_R
        Champion Level 3

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