NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

TestStand - Handling special characters in expression strings

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:

 

???

 

0 Kudos
Message 1 of 6
(6,797 Views)

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

Regards
Ray Farmer
0 Kudos
Message 2 of 6
(6,789 Views)

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

0 Kudos
Message 3 of 6
(6,785 Views)

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

Regards
Ray Farmer
0 Kudos
Message 4 of 6
(6,783 Views)
Ouch.
0 Kudos
Message 5 of 6
(6,781 Views)

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

Message 6 of 6
(6,755 Views)