05-10-2010 08:11 PM
Question: Is it possible to *easily* handle special characters (mainly " 's in TestStand expression strings)? I don't want to have to always escape every special character.
Reason: I have a step type which takes an expression... The expression may/not have double quotes.
Examples:
python string:
test = '''this is some "weird string with ' funny characters\dfdsf'''
tcsh shell string:
echo "'"'this is "a" test'"'"
'this is "a" test'
TestStand expression:
???
05-11-2010 01:14 AM
if you want quotes inside a string then you need to use the escape character
eg
test = '''this is some \"weird string with ' funny characters\\dfdsf'''
regards
Ray Farmer
05-11-2010 01:36 AM
Thanks for the response.
Like I mention in my post, I would rather not have to count on a user to use an escape character/s for their expressions. If this is the only way, it's a large limitation since it requires someone to manually edit every string passed to an expression (which seems to cripple the fundamental functionality of expressions). I'm sure there's some way to hack the string automagically in a previous step, and then hand off a string modified with escapes, but that adds yet another level of indirection/confusion.
There is absolutely no syntax to tell the teststand expression interpreter not to look at the contents of an expression string (similar to a string variable)?
Thanks,
noel
05-11-2010 01:42 AM
depending on what code module language you are using you could probably provide an interface that will forfill your needs. You just have to make sure that when you pass it back to teststand you will have to convert/add to ensure that your string is correctly represented back in Teststand.
regards
Ray Farmer
05-11-2010 01:49 AM
05-11-2010 10:18 AM
Noel,
If you want some UI you are writing to get a string from a user that you want to then put in a TestStand expression, you should do more than just put quotes around it, and you shouldn't require your user to have to put the quotes either. Instead, you should just let your end user enter any kind of string they want and your UI code should convert it back and forth from a TestStand expression to a string.
If you are using a recent version of TestStand you can call Engine.Utility.Escape(stringToEscape, EscapingOption_SurroundedByQuotes) to convert the string to an expression, and when you want to set the current string in your UI for the user to edit you should use Engine.Utility.Unescape(stringToUnescape, EscapingOption_SurroundedByQuotes) to convert from an expression back into a regular string.
Hope this helps,
-Doug