Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
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

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String Tweaking" Watch "String Tweaking" New topic

String Tweaking

Srikkanth Mohan

Joined: Apr 10, 2008
Posts: 5
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