This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Pages: 1 - Last Post: 10 Nov 22, 21:52 Last Post By: davidekholm
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
insertString crashes in Groovy
Posted: 10 Nov 22, 17:43
 
  Click to reply to this thread Reply
For making a menu I use in BeanShell this code:
	linkIndexPage= "<li><a class=\"nav-link\" " + preString.substring(indexHREF) + "</li>";			
topNavigation= insertString(topNavigation, linkIndexPage, indexUL+4);

If I convert this to Groovy I get this error message:
groovy.lang.MissingMethodException: No signature of method: java.lang.String.positive() is applicable for argument types: () values: []
Possible solutions: notify(), size(), tokenize() in navigation-bar.inc at line number 3

What should I change here?

Edit

insertString is coded as:
public static String insertString( String originalString, String stringToBeInserted, int index)  { 
        String newString = originalString.substring(0, index + 1) 
                           + stringToBeInserted 
                           + originalString.substring(index + 1); 
        return newString; 
}


Edited by: AndreWolff on 10 Nov 2022, 18:30
AndreWolff

Posts: 1,116
Registered: 14-Dec-2007
Re: insertString crashes in Groovy
Posted: 10 Nov 22, 18:42   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
This is the solution:
public static String insertString( String originalString, String stringToBeInserted, int index)  { 
        String newString = originalString.substring(0, index + 1)  + stringToBeInserted   + originalString.substring(index + 1); 
        return newString; 
}
davidekholm

Posts: 3,998
Registered: 18-Oct-2002
Re: insertString crashes in Groovy
Posted: 10 Nov 22, 21:52   in response to: AndreWolff in response to: AndreWolff
 
  Click to reply to this thread Reply
Ah, it turns out that the + operator needs the first argument on the same line. Interesting.
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums