EarthWeb
Developer.com
Site
windows 2000
visual c++
java
visual basic
javascripts
recommend it
 
Book
thinking in java
 
Interact
forum
guest book
jobs
jokes
what's new

share code
 
Resource
add resource
modify resource
new resource
 

[Internet Jobs]
-----
Java by E-mail:

Get the weekly e-mail highlights on Java!
-----

-

Replace a token by another in a string


Author: Real Gagnon
Author's WebSite: http://tactika.com/realhome/realhome.html


function replace(s, t, u) {
   /*
   **  Replace a token in a string
   **    s  string to be processed
   **    t  token to be found and removed
   **    u  token to be inserted
   **  returns new String
   */
   i = s.indexOf(t);
   r = "";
   if (i == -1) return s;
   r += s.substring(0,i) + u;
   if ( i + t.length < s.length)
     r += replace(s.substring(i + t.length, s.length), t, u);
   return r;
   }



Posted On: 10-Jul-1999

internet.commerce