Forum Discussion
RokuKC
7 years agoRoku Employee
There's no interpolation feature, but there are substitution and replacement APIs, which are about as good IMO.
or
or
You could also have a utility function that took a string and AA with key/value pairs and iteratively do the Replace calls, instead of hard-coding it as above.
Admittedly, all of these are more manual solutions than a generic interpolation feature would be, but in my experience they align pretty well with real world needs.
thing = "book"
color = "red"
print Substitute("My {0} is {1}.", thing, color)
' prints "My book is red."
or
thing = "book"
color = "red"
print "My %s is %s.".Format(thing, color)
' prints "My book is red."
or
thing = "book"
color = "red"
print "My ${thing} is ${color}.".Replace("${thing}", thing).Replace("${color}", color)
' prints "My book is red."
You could also have a utility function that took a string and AA with key/value pairs and iteratively do the Replace calls, instead of hard-coding it as above.
Admittedly, all of these are more manual solutions than a generic interpolation feature would be, but in my experience they align pretty well with real world needs.