How To | Send strings containing escaped characters to a third party device

Learn how to properly send strings containing escaped characters to a third party device and avoid errors from misinterpretation.

Updated at June 8th, 2023


It is often necessary to send strings that include escaped characters to external third party devices.  One example is the use of a carriage return or a line feed delimiter (normally written as \x0d or \r, and \x0a or \n respectively).  While the \n and \r will be interpreted properly within a scripted component, when coming from the Text Field from a separate component (ex. Custom Controls block) they will not. 

Those and other escaped characters (escaped by the usage of "\"), can easily be sent directly within the Command Buttons component.  However, if the string of text originates from a Text Field, the script will use the information on a character-by-character basis.  Thus, something as simple as "\x0d" gets translated as "\" + "x" + "0" + "d".

The solution to this is to call the Lua Interpreter to handle the string as it should.  This can be achieved with the following line of code:

formatted = load("return \""..textstring.."\"")()

where textstring is the text string on a character by character basis, and formatted  is the text string as it should be sent out, with the desired characters.