A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
OCA Java SE 8 Programmer I Study Guide 1Z0-808
this week in the
Joined: Apr 10, 2008
Apr 10, 2008 16:03:00
I need to delete and update a StringBuffer.My change is something like this
<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
int end="<LI class=\"someclass\">".length(); sb.delete(j,j+end); sb.insert(j,"<LI class=\"selected\">");
But I'm not able to do the second part of the massagin.
I tried this ,sb is a reference to the same Buffer
int disp=sb.indexOf("<LI class=\"selected\">Test12<UL>" ); String dispend="<LI class=\"selected\">Test12"; int dispend=dispent.length(); sb.delete(disp+dispend,disp+dispend+4); //+4 done for</UL> sb.insert(disp+dispend,"<UL style=''>");
But this doesn't work. Can you help me on this? Any better ways to do this?
Joined: Dec 31, 2004
Apr 10, 2008 16:48:00
I think you could do better using the replace() method.
Somewhat like this:
sb = new
int index = sb.indexOf("someclass");
And somewhat similar for the other part.
Joined: Nov 08, 2007
Apr 11, 2008 07:52:00
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 - frazerbilt.com
if (Posts < 30) you.read(
I agree. Here's the link:
subject: String Tweaking
Can you read this?
doubt: String formatting
Help with StringBuffer methods zero-based pls!!
Embedding Lists in XHTML
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015