File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

String Tweaking

Srikkanth Mohan
Greenhorn

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

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");
sb.replace(index,index+"someclass".length(),"selected");

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.

http://en.wikipedia.org/wiki/Java_API_for_XML_Processing
(Caveat emptor: I'm not familiar with any of them myself.)


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String Tweaking