Forum Discussion

Leanne_Zilka's avatar
Leanne_Zilka
New Contributor
13 years ago

I have a title that is a string and an integer, the integer needs to increment by 1 each time

I'm using jscript for our automation. I have a title field in a web app that needs to change after submission. The title is a string + an integer on the end, (ie, Automation Test 1) and the integer needs to increment by 1 each time, as you can't have submissions with the same name. 



First, can I read the original string and pull the ending integer out to save as a variable? And if not, any ideas how to do this? I'd rather not do an array, as this will be ran many, many times, and the array would become too big and take too long to process.
  • Not sure if this is what you mean but... This is what I would do::

    var str="Automation Test 1"; 





    function myFunction()


    {


     


    var n=str.slice(15,str.length);  



    // Slices right where the number is, with the number being any amount of digits. 


     





    Now, I'm a newby at JScript, but depending on your method of submission, upon submission, just do this ::



    n++;



    Then to change the string to the next string name::



    str = "Automation Test " + n;



    }



    CAKE :-)

  • sastowe's avatar
    sastowe
    Super Contributor
    JScript is JScript. There is nothing special about JSCript in Test Complete. Google string manipulation for jscript. Pull out the integer piece, incremenet it, and put it back.
  • sastowe's avatar
    sastowe
    Super Contributor
    OR if you prefer, Test Complete has a string manipulation wrapper object called aqString.

  • Leanne,


     


    Did Stephanie and Sean's suggestions help you?


     


    BTW, you can vote for the one you decided to use or you like (Was this post helpful?  -> Yes).


     

  • Yes, they did. The string slice worked perfectly, and was exactly what I was looking for!