check if a string contains a character code example
Example 1: java if string contains character
if (string.contains(character)
Example 2: javascript check if string contains a text substring
stringVariable.includes("Your Text");
Example 3: java string contains char
public static boolean contains_char (String main, char secondary)
{
boolean contains_result = false;
for (int i = 0 ; i < input.length () ; i++)
{
if (input.charAt (i) == secondary)
{
contains_result = true;
break;
}
}
return contains_result;
}
public static boolean contains_dualchar (String main, String secondary)
{
boolean contains_result = false;
for (int i = 0 ; i < input.length () ; i++)
{
if (input.charAt (i) == secondary.charAt (0))
{
if (input.charAt (i + 1) == secondary.charAt (1))
{
contains_result = true;
break;
}
}
}
return contains_result;
}
Example 4: 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;
}