• Post Reply Bookmark Topic Watch Topic
  • New Topic

Replacing Chars in certain places  RSS feed

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would I go about replacing characters based on their index value? For example, if I had the string: "-----", and I wanted to replace the character in the string which had the index value of 2, by 0, how could I do that? Is there a method of some sort?
 
Ranch Hand
Posts: 210
Ruby Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String does not have method to do what you want, you can still do them programmatically.
Check out StringBuffer, as I believe it has method that fits your need.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a good look at the String class documentation and the StringBuffer class documentation. In the String class, you might find the charAt and substring methods useful. In the StringBuffer class, you might find similar methods and the replace, and the setCharAt methods to be useful.
On a different note...
Parth S.,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy. (Note that a single character last name initial doesn't qualify.)
Thanks Pardner! Hope to see you 'round the Ranch!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!