Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

string replace inside of a JSP page

843840Sep 16 2002 — edited Sep 17 2002
I wrote the following function to replace single- and double-quote characters within a string, but I can't call the non-static StringBuffer.append method within this function. Could someone tell me how to replace all instance of a single character within a string with a different string in a JSP page?

<%!
public final String replaceString( String stringIn, char replaceMe, String withMe ) {
int i=0,
int len = stringIn.length();

StringBuffer newSB = new StringBuffer("");

if ( withMe.equals("") )
for ( i = 0 ; i < len ; i++ ){
if ( replaceMe == stringIn.charAt(i) ) {
StringBuffer.append(new Character(stringIn.charAt(i)).toString());
}
}
else
for ( i = 0 ; i < len ; i++ ){
if ( stringIn.charAt(i) == replaceMe ) {
StringBuffer.append(withMe);
}
}
return newSB.toString();
}
%>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 15 2002
Added on Sep 16 2002
1 comment
199 views