check if string has substring code example
Example 1: if str contains jquery
if (str.indexOf("Yes") >= 0)
if (str.toLowerCase().indexOf("yes") >= 0)
Example 2: check if string contains substring sql
Declare @mainString nvarchar(100)='Amit Kumar Yadav'
---Check here @mainString contains Amit or not, if it contains then retrun greater than 0 then print Find otherwise Not Find
if CHARINDEX('Amit',@mainString) > 0
begin
select 'Find' As Result
end
else
select 'Not Find' As Result
Example 3: how to check if a string contains a character
public static boolean containsIgnoreCase(String str, char c) {
str = str.toLowerCase();
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == Character.toLowerCase(c)) {
return true;
}
}
return false;
}