Other languages offer you string interpolation of variables like this:
:log warn "${testStr}2"
or
:log warn "{$testStr}2"
Of course not working in ROS scripting. First example is syntax error and the second one works, but outputs the braces. I guess OP does not want the braces.
Try:
:log warn "$(testStr)2"
Regardless of example. It is a valid question to ask. I guess the stupid example is just to better understand OPs question. I don’t want to see/understand complicated real-life code for just answering such a simple question. So, colin, all fine with your sample.
“Use” instead of “Try”. Because I actually verified and tried myself before posting. But on ROS 7.15.3 tested. OP did not say which ROS version. Can’t say if it is compatible with v6 or older V7. Now understand the term “Try”?
I do not use global, because on OP is using locals. I test, one moment please.
what t. f. ???[admin@TEST-v7] > :local testStr “198” ; :put “$(testStr)2”
2
[admin@TEST-v7] > :local teststr “198” ; :put “$(teststr)2”
1982
if the var name containing one at least one upper case… do not work…
Probably because this (is for the array):
Warning: Key name in array contains any character other than lowercase character, it should be put in quotes
Notice: " must not be escaped on string, is parsed first $“…” than the rest of the string.
eg:
:log warn “$“test_Str”$”“2”
$“test_Str” is replaced with his contents 198 and $“” do not exist, so, is replaced with string of zero length (that is not the same as a string with 0x00 character inside) =>
:log warn “1982”
so, is logged only 1982 =>
:log warn “1982”
For curiosity, the first two soluctions do the same result once parsed from “compiler” (concat $test_Str and 2):
(evl /localname=$test_Str;value=198);(evl /log/warningmessage=(. $test_Str 2))
the third, just add empty string (the $ ) to the code (concat $test_Str and $ and 2):
(evl /localname=$test_Str;value=198);(evl /log/warningmessage=(. $test_Str $ 2))
So, for script efficency, is better the first two (on this case) and not the third.
I’m not good at english, so sorry for my bad example.
But i think @infabo understood what i mean, and i got the answer from other replies.
So thanks to all.