Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

string replace function

1,257 views
Skip to first unread message

chris idr

unread,
Jan 12, 2009, 7:17:57 AM1/12/09
to rhino Dev
Hi all,

can anyone tell me if rhino properly supports the replace function in
javascript, as i have an example and it doesn't seem to.

all it seems to do is redirect the call to java replace.

i have a replace(/,/gi,";"); (the g means replace all and the i means
ignore case)

can anyone tell me how to make this work properly, or when it might be
added.

if its not going to be added anytime soon, then could someone be kind
enough to tell me what to change in rhino itself so i can get it to
work, and i will submit my fix to you for inspection

regards
chris wade


Norris Boyd

unread,
Jan 12, 2009, 11:12:31 AM1/12/09
to

The replace function is completely implemented as far as I know:

js> var s = "Hi, Mom";
js> s.replace(/m/gi, 'b');
Hi, bob

What isn't working for you?

--Norris

chris idr

unread,
Jan 12, 2009, 6:21:25 AM1/12/09
to rhino Dev

Charles Lowell

unread,
Jan 13, 2009, 8:10:12 AM1/13/09
to
On Jan 12, 7:17 am, chris idr <ch...@idrsolutions.com> wrote:


Chris,

You have a reference to a java.lang.String. Try wrapping it in a
javascript string:

Rhino 1.7 release 1 2008 10 20
js> s = new java.lang.String("Hi Mom")
Hi Mom
js> s.replace(/m/gi,'b')
js: "<stdin>", line 3: 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)
at <stdin>:3

js> new String(s).replace(/m/gi,'b')
Hi bob
js>

0 new messages