How can I escape "=" as part of a column name?
I need to implement a "select where" statement and I am building it as a string, which involves multiple column names. But when it evaluates it is attempting to interpret the "=" as an assignment. My column names are like: "COND=TEMP".
Below the section of the script I use:
select_string = ":Test Name == benchNameToCompare";
//For each column in the map table, if the column name is a COND add it to the select criteria
For( j = 1, j <= numOfColumns, j++,
Current Data Table(correlationMapTable);
currentColumnName = correlationMapTable<<Get Column Names();
If(Contains(currentColumnName[j],"COND_")>0,
theValue = currentColumnName[j][i];
colName=currentColumnName[j];
select_string = select_string || " & As Column(correlationMapTable," || char(currentColumnName[j]) || ") == " || char(currentColumnName[j][i]);
);
);
select_string = "benchDataTable << select where(" || select_string || ")";
eval(parse(select_string)); //Here is complains if I have "=" as part of the column name.
benchDataTable << Subset(( Selected Rows ), Output Table Name("Filtered Bench Table"));
Thanks in advance!
I'll be honest, this script has a lot of issues. My head hurts just thinking about debugging it.
So I'm not going to, but essentially your issue is this:
= doesn't need to be escaped what you need to escape is parenthesis quotation marks. AKA:
eval(parse("dt << Select Where(Column("Cond=Temp") == 2)"));
needs to become:
eval(parse("dt << Select Where(Column(\!"Cond=Temp\!") == 2)"));
Hello msharp,
Thank you for taking the time to respond. So could you clarify that the required escape sequence is \! <column name goes here> \! ?
As a C# programmer, my head hurts a lot just learning JSL :-)
Regards,
B
Hey, breinoso,
Yeah, I have not been around long enough to know the origin of the escape characters in JSL, but they indeed start out with "\!". To insert a newline in a string, it's "\!n". To prevent a quote from being seen by JMP as the end of a string, make it \!". (And I think msharp meant to say "what you need to escape is quotation marks").
And, yes, coming from other languages to JSL can be a little off-putting ;-).
HTH,
Eric
Yes, quotation marks. Thanks for the catch.
To learn more about escape characters and the nuances of JSL, you can reference the Scripting Guide which is really well put together. Help>>Books>>Scripting Guide. (Escape characters are on p.87). If you are just wondering about syntax the Scripting Index is more helpful. Help>>Scripting Index.
A couple things to point out,
For numbers in If() statements, JSL responds truthy to anything other than 0. So If(Contains(currentColumnName[j],"COND_")>0, is the same as If(Contains(currentColumnName[j],"COND_"),
This:
//For each column in the map table, if the column name is a COND add it to the select criteria
For( j = 1, j <= numOfColumns, j++,
Current Data Table(correlationMapTable);
currentColumnName = correlationMapTable<<Get Column Names();
If(Contains(currentColumnName[j],"COND_")>0,
theValue = currentColumnName[j][i];
colName=currentColumnName[j];
would be better written:
//For each column in the map table, if the column name is a COND add it to the select criteria
For( j = 1, j <= numOfColumns, j++,
colName = Column(correlationMapTable, j) <<Get Name;
If(Contains(colName,"COND_"),