I've been recently experimenting and learning with writing scripts for Aris, and I've hit a wall with this one.
My problems is this, I'm trying to compare a list of models that I extract with a report. To compare their names in an easier way, I was trying to simplify their names (all lower cases and substitute every white space with underlines). I'm having a hard time with this last transformation. I've tried to use the "replace()" function, but an error message is shown when I do it.
The snippet of code that I was using to simplify the names of the models is:
var model = oObjOccList[0].Model(); var modelExtract2 = model.Name(idioma); var modelExtract = modelExtract2.replace(/\s/g, "_") var modelName = modelExtract.toLowerCase();
When I try to run it, it gives me:
"The choice of Java constructor replace matching JavaScript argument types (function, string) is ambiguous; candidate constructors are:
class java.lang.String replace(char, char)
class java.lang.String replace(java.lang.CharSequence, java.lang.CharSequence)"
What gives?
I'm might be thinking it wrong, but if I put the quote marks, won't it interpret as to literally look for "/\s/g", instead of the regular expression of white spaces?
Anyway, I've tried just to be sure, and it did not replace the white spaces for underscores as I intended...
I'm might be thinking it wrong, but if I put the quote marks, won't it interpret as to literally look for "/\s/g", instead of the regular expression of white spaces?
Anyway, I've tried just to be sure, and it did not replace the white spaces for underscores as I intended...
Can you please give any suggestion for below problem:
var oFile=File; // Excel File
g_XLSWorkbook=Context.getExcelReader(oFile);
var XLSSheet=g_XLXWorkbook.getSheetAt(0); //Excel at sheet index1
var data=XLSSheet.getCell(0,0).getCellValue().toLowerCase().Replace(/[^A-Za-z]/g,""); //extracting cell data and trying to remove all special characters.
I have tried but failed to use replace() method , Even tried your code ,It's not working for me .
Error :it is not able to identify 'g'.
for reference the code is:
var oreg= new RegExp([^a-zA-Z],g);
var testdata=XLSSheet.getCell(0,0).getCellValue().toLowerCase().replace(oRegExp,"")
Yes sure, this would take the expression literally, but I think if you use something like \/ it has a special meaning then...
But anyway - what means the "g" in the new RegExp ?
new RegExp(" ",g)
And why don't you use use
var modelExtract = modelExtract2.replace(" ", "_")
BR Robert
Thanks for the suggestion :) . I have found out the reason why 'replace()' was not working. The problem was with the 'type' . The data which I am extracting from the excel is of type Object ( String) . In order to use 'replace()' we should have string data. So I have type casted Object to String to make it work.
I have also tried with your code. It was not working for the same reason. After type casting , it was working.
Thank you so much for your support :)