BookmarkSubscribeSubscribe to RSS Feed

How use Substitute for Escape Sequences in Double Quotes?


Community Trekker


Jun 23, 2011

How to substitute a literal "escape sequence" within a double quoted string?  Problem I'm having is that JMP always wants to evaluate the "escape sequence" and not give me its literal character representation:

Source string:

myStr = "C:\temp\myfile.csv";

What I want:

myStr = "C:\!\temp\!\myfile.csv";

The following methods don't work or at least don't appear so when I check them in the Log window (wonder, is that my problem maybe, that the Log window always evaluates?):

myStr = Substitute(myStr,"\","\!\"); ==>doesn't work as it evaluates "\!\" and turns it back into a "\"

myStr = Substitute(myStr,"\","\" || "!" || "\"); ==>doesn't work as it evaluates this again and gives me double "\!\" essentially

Any ideas?  --dj


Community Trekker


Jan 26, 2012

I can't test this, since I don't have JMP, but I would try a two-step approach:

myStr = Substitute(myStr, "\", "\ ! \");

myStr = Substitute(myStr, " ! ", '!');

Good luck.


Super User


Jun 23, 2011

To avoid evaluating escaped characters the escape itself must somehow be escaped.

You are right, the log output may be confusing. Run this code and compare how the ways the log and the window present the strings:

myStr = "C:\temp\myfile.csv";

newStr1 = Substitute( myStr, "\", "\!\" );

newStr2 = Substitute( myStr, "\", "\[\!\]\" ); // "Escape the escape""

// The log evaluates strings; newStr2 looks weird in the log because of the "escaped escape"

Show( newStr1, newStr2 );

// however, in another context newStr2 shows it real value, or doesn't it?

nw = New Window( "myStr", String Col Box( "new strings", {newStr1, newStr2} ) );