Actually, in your example, calling x.replace('y','a') would work, but I
suspect that was only a simplification.  Try the following:
    (*Chris*)

  /**
   * Replace all occurrances of a String with another String
   *
   * @param a The String to be processed
   * @param b The String to be removed
   * @param c The String to be used instead
   * @return The processed String
   */
  public static String replace (String a,String b,String c) {
    int pos = a.length();
    int len = b.length();
    StringBuffer buf = new StringBuffer(a);
    while((pos = a.lastIndexOf(b,--pos)) != -1) {
      buf.delete(pos,pos + len);
      buf.insert(pos,c);
    }
    return buf.toString();
  } //replace

----- Original Message -----
From: "Rama" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, December 19, 2001 8:46 AM
Subject: [JSP-INTEREST] string replace


> How to replace some string in string?
>
> String x = "var1=xx&var2=yy&var3=zz"
> i want to replace yy with aa
>
> the replace function doesn't seem to work.
>
>
> Rama
>
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://archives.java.sun.com/jsp-interest.html
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.jsp
>  http://www.jguru.com/faq/index.jsp
>  http://www.jspinsider.com


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to