Column Expression Node >> Java Script Integer Double issue

Hi,

I have a Column (“Col2”) e.g.
123(43214)
234
123

where some cells have Brackets (…)
I want to remove the Brackets and everything within them so I use the Column Expression Node and wrote a script. Script is included further down and here is where I get an error I can’t fix

InStrPosition2=InStrPosition1+1
The Error message is that one integer adding to another integer and the compiler is telling me that I can’t assign a Double to an integer…

====================================================
var InStrPosition1=1;
var InStrPosition2=1;
var Cell=column(“Col2”);
var StrReplacement="";
var StrLength=1
StrLength=length(Cell);
InStrPosition1=indexOf(Cell,"(",InStrPosition1);

if (InStrPosition1==-1) {(InStrPosition1=0)}
else
{
/ ISSUE IS HERE/**
InStrPosition2=InStrPosition1+1;
if (InStrPosition2 < StrLength)
{
InStrPosition2=indexOf(Cell,")",InStrPosition2);
}
if (InStrPosition2=-1) {}
else
{
StrReplacement=substr(Cell, InStrPosition1, InStrPosition2-InStrPosition1)
Cell=replace(Cell, StrReplacement, “”)
}
}

Hi @iCornerstone,

I am not an expert in javascript types and also find them confusing at times. I could fix your expression by adding a toInt() to this line InStrPosition2=indexOf(Cell,")",toInt(InStrPosition2));.

However, it did not return the numbers. If you just want to remove everything inside the brackets a simple regexReplace(column("Col2"), "\\(.*", "") would do the job.
Cheers,
Johannes

1 Like

Thanks the toInt() worked.
Your suggestion for the other approach is interesting. Unfortunately it removes everything after the “(” and not everything between “(” and “)”.
Very helpful though

Hi,

regexReplace(column("Col2"), "\\(.*\\)", "")

You could also use a String Manipulation to do that.
regexReplace($Col2$, "\\(.*\\)", "")

Best,
Armin

3 Likes

brilliant

1 Like