• Post Reply Bookmark Topic Watch Topic
  • New Topic

string.replace limited to only one character.  RSS feed

 
Steve Nix
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to use string.replace or another method to remove the occurrence of more than one character. In other words, how could I remove the word "cat" from the following string:
myString = "That dog ate the neighbors cat!"
 
Junilu Lacar
Sheriff
Posts: 10879
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The StringBuffer class has methods that will let you do what you want. Check out the delete() method.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!