• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String Tweaking

 
Greenhorn
Posts: 16
jQuery AngularJS Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

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

Before:
<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?
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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");
sb.replace(index,index+"someclass".length(),"selected");

And somewhat similar for the other part.
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you'd ultimately be best server to learn one of the XML packages that helps manipulate/model XML.

http://en.wikipedia.org/wiki/Java_API_for_XML_Processing
(Caveat emptor: I'm not familiar with any of them myself.)
 
reply
    Bookmark Topic Watch Topic
  • New Topic