you can use a regular expression to do this quickly and easily.

i use regexp from GNU (http://www.gnu.org).  i think sun and IBM also
may have regular expression packages.

-steve


-----Original Message-----
From: Phil Campbell [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 11, 2000 3:10 PM
To: [EMAIL PROTECTED]
Subject: Re: Replace a character (or group of characters)?


Ken:

String.replace( '~', x ), where x is the char value for new line (\n), may
work, but it only replaces char occurrences within a String. I prefer
another route...

Something like this may prove more useful:

    String s = "This~is~a test of~parsing text" ;
    String sOld = "~" ;
    String sNew = "\n" ;
    int itmp = -1 ;
    while ( ( itmp = s.indexOf( sOld )  ) >= 0 )
        s = s.substring( 0, itmp) + sNew + s.substring( itmp +
sOld.length() ) ;

Hope this helps.

Phil Campbell


p.s.:    Are you building a parser? if so, we may have parser utility class
that may help -- email me.

-----Original Message-----
From: Ken Martin <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Tuesday, July 11, 2000 12:51 PM
Subject: Replace a character (or group of characters)?


>Is there a way to take a string of text like:
>
>This~is~a test of~parsing text
>
>...and replace each tilde with a line break?
>
>So I get...
>
>This
>is
>a test of
>parsing text
>
>TIA from a newbie who will be buying "Core Servlets..." soon.
>
>Ken Martin
>
>===========================================================================
>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
>

===========================================================================
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

===========================================================================
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

Reply via email to