• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

StringBuffer Question

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to delete all characters in a StringBuffer from the beginning through the first occurance of a newline character. Essentially, I am deleting the first line.
I am aware of the delete method that takes the start and end, but I do not know how to determine the end index, or the first occurrance of the newline. There does not seem to be a method to find the index of a particular character, but I know this should to be an easy thing to accomplish.
Can someone show me the code that will do this delete.
Thanks in advance for the help,
Rob
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob,
This may not be the optimal code, but this code works!
 
Rob Levo
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vikas Varma:
Hi Rob,
This may not be the optimal code, but this code works!


Thanks!!
Does anyone know of a way to do it without converting toString, I think that is where it might slow, this StringBuffer could be quite large.
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another method to consider:

Don't know if its any more efficient. Cheers, Neil
(And my example doesn't actually use a StringBuffer at all . Perhaps you need to consider if you need a StringBuffer at all)
[ October 03, 2002: Message edited by: Neil Laurance ]
 
Neil Laurance
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Umm, and an example using StringBuffer:

Cheers, Neil
 
Rob Levo
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
It just seems like there should be something analogous to indexOf for StringBuffer, but I guess not for some reason.
 
Rob Levo
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Neil Laurance:
Umm, and an example using StringBuffer:

Cheers, Neil


Neil,
Perfect!!!
Thanks,
Rob
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic