I’m trying to split a java string in a Rhino javascript program
var s = new java.lang.String("1 2 3");
s.split();
which give me the error
js: Can't find method java.lang.String.split().
The Rhino docs mentioned that all the javascript String.prototype methods (like match, split, etc.) are available on java string if they’re not already provided by java.lang.String. Any ideas on what’s going on here?
Take a look at the Java docs: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html
Doesn’t seem to be a 0 parameter constructor for the split method. You gotta pass it a regular expression.
Also, for further clarification, the split method returns a string array, it’s not a void method like the way you’ve used it in your sample code.