Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string.replace limited to only one character.

 
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
Bartender
Posts: 7557
52
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic