Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I see if a substring exists inside another string in Java 1.4?

How can I tell if the substring "template" (for example) exists inside a String object?

It would be great if it was not a case-sensitive check.

like image 884
joe Avatar asked Mar 26 '09 21:03

joe


1 Answers

String.indexOf(String)

For a case insensitive search, to toUpperCase or toLowerCase on both the original string and the substring before the indexOf

String full = "my template string";
String sub = "Template";
boolean fullContainsSub = full.toUpperCase().indexOf(sub.toUpperCase()) != -1;
like image 118
John Ellinwood Avatar answered Sep 28 '22 09:09

John Ellinwood