Suppose i have a string say "ABCD-78" in a text file & have to increment the last two digits with a new one & replace it in the next file so that it looks like "ABCD-80".How can i do this this? are there any replace strings command?
In this case you have write a code using the string functions available in WinRunner. Something like this.
str1 = "ADBC-78";
x = length(str1); #assuming the length varies and only the last two are numeric
str2 = substr(str1,1,x-2); # to extract "ADBC-"
Num1 = substr(str1,(x-1),2); #To get '78'
Num1 = Num1 + 1 # to add 1 to make '79' etc...
#Append to the base string
y = y & Num1; # "ADBC-79"
The solution will always be a bit of coding. If the "-" is the stable part of your string (and the string before the "-" or the number of digits after the "-" might change) you could use the split-command to replace the number at the end:
</font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">function replaceNumber (in str, in newNumber)
split(str, arr, "-"
# arr contains the previous number,
# you could use this for incrementing, ...
return (arr & "-" & newNumber);
}</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">Note that this is a very simplified solution without any safety checks...