Interview Questions

How to convert variable from ascii to string?

Mercury WinRunner FAQ


(Continued from previous question...)

How to convert variable from ascii to string?

If you want to generate characters from their ascii codes, you can use the sprintf() function, example:
sprintf("%c",65) will generate "A"
If you want to add a number onto the end of a string, you can simply stick it next to the string, example:
ball=5;
print "and the winning number is: " ball;
Putting them together can get some interesting effects, example:
public arr[] = {72,101,108,108,111,32,102,114,111,109,32,77,105,115,104,97};
msg = "";
for(i in arr) msg = msg sprintf("%c",arr[i]);
print msg;
Hmmm, interesting effect from the elements not being in order. I'll try it again:
msg = "";
for(i=0;i<16;i++) msg = msg sprintf("%c",arr[i]);
print msg;

(Continued on next question...)

Other Interview Questions