NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

literal string

Where can I find how to put a literal string into an expression? When I search for TestStand string literal, I find nothing.

Thanks.

0 Kudos
Message 1 of 10
(4,946 Views)

I'm not totally sure what you mean by literal string, but I'm thinking you just need to put quotes around your string.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 10
(4,926 Views)

By literal string, I mean don't unescape any slash codes.

0 Kudos
Message 3 of 10
(4,919 Views)

@StephenGerads wrote:

By literal string, I mean don't unescape any slash codes.


Ah.  Yeah, I've had that problem as well.  I ended up just using the double slash (\\) whenever I had a slash in my string.  I hope there's a better solution.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 10
(4,917 Views)

I know there is a way to do it in the newer TS versions. I wish details were easy to locate with search "TestStand literal string".

0 Kudos
Message 5 of 10
(4,913 Views)

You can either use double back-slashes (to escape the backslashes themselves), or, in TestStand 2012 and higher, you can use the @ symbol before the string literal to avoid the unescaping. For example:

 

@"my string w\ith\ backslashes"

 

The following is from the expression browser help in the "Operators/Functions" tab under Constants->Other:

 

"Add an '@' before the enclosed quotes to turn a string constant into an unescaped string constant. Unlike for regular string constants, backslashes are left as is instead of specifying an escape sequence. Use "" for " within an unescaped string constant."

 

Hope this helps,

-Doug

Message 6 of 10
(4,901 Views)

Alternatively, you can use the RunState.Engine.Utility.Escape() method to emulate the behavior of the "@" symbol in TestStand 2010 SP1 and earlier:

 

RunState.Engine.Utility.Escape("\test",0)

Al B.
Staff Software Engineer - TestStand
CTA/CLD
0 Kudos
Message 7 of 10
(4,864 Views)

Al B,

Can you arrange to have it easy to find this information in help?

Thanks.

Steve

0 Kudos
Message 8 of 10
(4,856 Views)

Hi Steve,

 

For future TestStand versions, we would recommend using the "@" approach as mentioned by dug9000, so there are no plans to further document the escape method I mentioned.  However, you can find information on expression operators and functions in the TestStand help (Expression Functions and Expression Operators topics) or in the description field within the expression browser. 

Al B.
Staff Software Engineer - TestStand
CTA/CLD
0 Kudos
Message 9 of 10
(4,848 Views)

Hi, I did a bit more testing with the utility.escape method I suggested, and it doesn't behave exactly in the same way as the "@" operator like I originally stated.  The difference is in the case when a backslash is not forming a special character.  In this case, the unescape method adds an additional backslash, for example:

 

  • @"C:\windows\test" - will return "C:\windows\test"
  • RunState.Engine.Utility.Escape("C:\windows\test",0) - will return "C:\\windows\test"

Both of these results will work with a file open operation, but I would suggest using the "\\" method with TestStand 2010 or earlier rather than the unescape method just to be sure you are not getting unexpected double backslashes.

Al B.
Staff Software Engineer - TestStand
CTA/CLD
0 Kudos
Message 10 of 10
(4,830 Views)