How to escape single quote, speechmarks in encoded text from textEndode function?

Hi folks,

I have been working with SenseTalk for some time but I haven’t found a way to handle the scenario where the textEncode function returns a string that contains a quote (') or speechmark character (") that needs to be escaped before that variable is used to fill in a password field. The use case is that I’m connecting to a SUT and using it to login to another host, supplying a username and password.

I know the cleartext for the password, but it isn’t appropriate to embed it in my script in cleartext, so the obvious solution is to use textEncode on it once only, store the variable in the script in its encoded format, and supply it at the login prompt with a call to textDecode at the point where the login dialog needs it.

The problem I have is that the encode/decode function can generate strings with an unwanted and premature string terminator character like “'” in them - which I can’t find an easy way to escape, with the result that all the password decoded text after that character doesn’t get passed in the login credentials.

In the C programming language, any special character in a string can be escaped with a backslash - so that the string “Hello "World” will be presented as Hello "World when the string is next used. I’m looking for the same behaviour, where a backslash before a string termination character tells the interpreter to treat the next character as a literal value, not a terminator.

Does anyone have a solution for this please?
Thanks

Right. SenseTalk strings are normally literal, with backslashes treated as backslashes, etc. There are at least 3 simple options for including quotes and other characters in a string. First, you could use << and >> to quote the string instead of " ":

set password to <<Hello "World">>

Of course, that won’t solve the problem if the password also contains “>>”, so a better solution is to use a block quote enclosed in {{ and }}:

set password to {{
Hello "World"
}}

Using escape characters is less readable and more prone to making mistakes, but if you really prefer that approach you can do this by using @ before the quoted string:

set password to @"Hello \"World\""

Many thanks! Problem solved :slight_smile: