Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use 'if' to condition and ignore a word in a particular sentence?

How can I construct a condition that if a phrase has the name "x", then "x" is ignored when the phrase is displayed?

Example:

if(item.contains("Text"))
{
    //Then ignore "Text" and display the remaining mill
}
like image 479
Tisco Avatar asked Dec 05 '22 14:12

Tisco


1 Answers

You can easily use :

String item = "This is just a Text";
if (item.contains("Text")) {
    System.out.println(item.replace("Text", ""));
}
like image 131
YCF_L Avatar answered Dec 08 '22 04:12

YCF_L