Profile picture for user celso.mattheus

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?

by Robert Goldenbaum
Badge for 'Question Solver' achievement
Posted on Mon, 11/09/2015 - 16:07

Hi,

hm, I always use it like this:

var modelExtract = modelExtract2.replace("/\s/g", "_")

BR Robert

0
by Celso Mattheus Cantanhede Silva Author
Posted on Mon, 11/09/2015 - 18:08

In reply to by rgoldenbaum

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... 

0
by Celso Mattheus Cantanhede Silva Author
Posted on Mon, 11/09/2015 - 18:21

In reply to by rgoldenbaum

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... 

0
by Ariene Kroeze
Posted on Mon, 11/09/2015 - 19:02

Try:

var oRegExp =  new RegExp(" ",g)
var modelExtract = modelExtract2.replace(oRegExp, "_")

br, Ariene       

0
by Celso Mattheus Cantanhede Silva Author
Posted on Mon, 11/09/2015 - 20:15

In reply to by Ariene Kroeze

Thank you very much, Ariene! It worked. 

Since I'm still in a novice,I admit I did not know that there were a Regular Expression object. That will be very useful. 

0
by Praveen Sharma
Posted on Mon, 04/23/2018 - 14:34

In reply to by Ariene Kroeze

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,"")

 

 

 

 

 

0
by Robert Goldenbaum
Badge for 'Question Solver' achievement
Posted on Tue, 11/10/2015 - 07:59

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

0
by Praveen Sharma
Posted on Tue, 06/05/2018 - 06:40

In reply to by rgoldenbaum

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 :)

0

Featured achievement

Rookie
Say hello to the ARIS Community! Personalize your community experience by following forums or tags, liking a post or uploading a profile picture.
Recent Unlocks
  • Profile picture for user frankweise
  • Profile picture for user Henrik Buckler
  • Profile picture for user UffeK
  • SS
  • MZ
  • PacMan

Leaderboard

|
Nobody has collected any points yet this week. This is your chance to become one of the top 5 on this week's leaderboard.
icon-arrow-down icon-arrow-cerulean-left icon-arrow-cerulean-right icon-arrow-down icon-arrow-left icon-arrow-right icon-arrow icon-back icon-close icon-comments icon-correct-answer icon-tick icon-download icon-facebook icon-flag icon-google-plus icon-hamburger icon-in icon-info icon-instagram icon-login-true icon-login icon-mail-notification icon-mail icon-mortarboard icon-newsletter icon-notification icon-pinterest icon-plus icon-rss icon-search icon-share icon-shield icon-snapchat icon-star icon-tutorials icon-twitter icon-universities icon-videos icon-views icon-whatsapp icon-xing icon-youtube icon-jobs icon-heart icon-heart2 aris-express bpm-glossary help-intro help-design Process_Mining_Icon help-publishing help-administration help-dashboarding help-archive help-risk icon-knowledge icon-question icon-events icon-message icon-more icon-pencil forum-icon icon-lock