Liart Junior wrote:
>
> I need a method to replace more than one character.
>
> Example:
>
> String test = "I need help";
> test.<method name>("help", "a function");
>
> returns = "I need a function."
>
> The method replace(), is used do replace a character to another character.
> I need replace a string to another string.
>
> Thanks
Gidday Liart,
here is the code I use, it has not been thoroughly tested but I have
used it for several years without a problem
String test = "I need help";
test = au.com.coolcat.TString.replace(test, "help", "a function");
/**
* replace all String flag in String input with String repacement
<br>
* usage: au.com.coolcat.TString.replace(String input, String flag,
String replacement) <br>
*/
public final static String replace(String input, String flag, String
replacement) {
int pos = 0;
int flagLen = flag.length();
StringBuffer str;
while( (pos = input.indexOf(flag, pos)) != -1 ) {
str = new StringBuffer(input.substring(0, pos));
str.append(replacement);
str.append(input.substring( pos + flagLen ));
input = str.toString();
pos++;
// System.out.println(input);
}
return input;
}
cheers pb...
--------------------------------------------------------------------------------------
Peter Blakeley
[ coolcat.com.au ]
this(); // call my birth to check that all that is needed is.
;-})
.
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets