It’s World Statistics Day! To honor the theme of the day, the JMP User Community is having conversations about the importance of trust in statistics and data. And we want to hear from you! Tell us the steps you take to ensure that your data is trustworthy.
Choose Language Hide Translation Bar
Level V

How use Substitute for Escape Sequences in Double Quotes?

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

Level I

Re: How use Substitute for Escape Sequences in Double Quotes?

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 ms
Super User

Re: How use Substitute for Escape Sequences in Double Quotes?

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} ) );

Article Labels

    There are no labels assigned to this post.