File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Tweaking

 
Srikkanth Mohansundaram
Greenhorn
Posts: 16
AngularJS Chrome jQuery
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Bill Shirley
Ranch Hand
Posts: 457
  • 0
  • Mark post as helpful
  • send pies
  • 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.)
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic