File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes String Tweaking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Tweaking" Watch "String Tweaking" New topic

String Tweaking

Srikkanth Mohansundaram

Joined: Apr 10, 2008
Posts: 16

Hi all,

I need to delete and update a StringBuffer.My change is something like this

<LI class="someclass">Test12<UL>

After Tweaking

<LI class="selected">Test12<UL style="display:block'>

Till now i've been able to change the first part of the class, with something like this
, j refers to the start index of the String.

But I'm not able to do the second part of the massagin.

I tried this ,sb is a reference to the same Buffer

But this doesn't work. Can you help me on this? Any better ways to do this?
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
I think you could do better using the replace() method.

Somewhat like this:

sb = new StringBuffer("<LI class=\"someclass\">Test12<UL>");
int index = sb.indexOf("someclass");

And somewhat similar for the other part.
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
I think you'd ultimately be best server to learn one of the XML packages that helps manipulate/model XML.
(Caveat emptor: I'm not familiar with any of them myself.)

Bill Shirley - bshirley -
if (Posts < 30) JavaRanchFAQ);
I agree. Here's the link:
subject: String Tweaking
It's not a secret anymore!