How to combine a string and a variable into one string?
finn
I would like to combine a string together with a variable.
I tried it this way:
Function Test()
string wavename = “wave”
variable number = 1
string together
together = wavename + number
Print together
End
I would like the Function to print “wave1” but it does not work. How can I do this?
Cheers,
Finn
String name = "wave"
Variable number = 1
// Simple solution
String together = name + num2str(number)
Print together
// More powerful - see documentation for sprintf
sprintf together, "%s%d", name, number
Print together
End
sprintf is general and powerful. In this example it substitutes the contents of name for %s. It then converts number into text and substitutes that text for %d. It stores the result in together.
See the documentation for sprintf for details.
October 8, 2011 at 09:39 am - Permalink
October 9, 2011 at 12:19 am - Permalink