Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

StringBuffer help  RSS feed

 
Tyler Selby
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I and in an intro to object-based programming class and and having a problem with using StringBuffer object. I need to append a the object but the substring need to be inserted in to the middle and I can't figure out what i am doing wrong. I just need an i dea of what parameters i need.

thanks 4 the help

tyler
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

Have you looked at the API documentation for StringBuffer? What exactly have you tried?

(PS: Please don't use "4" in place of "for." Thanks!)
 
Sanjaya Sugiarto
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method you need is insert(int offSet, Object obj).

Example:

StringBuffer sb = new StringBuffer("Helo World");
sb.insert(2, new StringBuffer("l")); //inserting as Object from type StringBuffer

Or

StringBuffer sb = new StringBuffer("Helo World");
sb.insert(2, "l"); //inserting as Object from type String (String is an object)
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!