| Author |
same stuff
|
vivek sivakumar
Ranch Hand
Joined: Aug 09, 2001
Posts: 187
|
|
okay thanks for ur previous posts, okay let us take a example if i have say String lo = "advr$o&" ; i want to replace $ by string "ror" and & by "roro" how can i do it thro String buffer as u said . might be next time i get the value of lo to be "$ghg& " so the position if special characters is not fixed , can u give a snippet for this.
|
SCJP, SCWD <br />A farmer learns more from a bad harvest than a good one.
|
 |
Dave Vick
Ranch Hand
Joined: May 10, 2001
Posts: 3244
|
|
vivek Check out the StringBuffer replace method. What you need to do is iterate over the Stringbuffer to find the characters you're looking for then do a replace. the trick is to increase your counter so that you go beyond the String you just inserted or you'll replace the characters in that too if they match what you're looking for. If you want that behavior then you dont need to increment i except by 1 at the end of the while loop. Check out this code: hope that helps
|
Dave
|
 |
 |
|
|
subject: same stuff
|
|
|