-1

May i ask, how do i remove words and letters from a string?

Example: is, are Example: -ing.

A sentence: A wolf is eating a sheep.

becomes: A wolf eat a sheep.

Thanks!

Lancer
  • 13
  • 1
  • 2

1 Answers1

4

Use replace method

String str = "A wolf is eating a sheep.";

str = str.replace("ing","");

or

str = str.replace("eating","eat");
Harshit
  • 5,147
  • 9
  • 46
  • 93
  • Thanks! Is it possible not to specify the string in the first place and let the removal take place by itself? – Lancer Aug 22 '15 at 03:23
  • How will the code know what you want to remove ? You will have to specify the removable or replaceable string in the first place!! – Harshit Aug 22 '15 at 03:26