str1.toLowerCase().contains(str2.toLowerCase())
works except it returns true for "11 contains 1" but I want it to search for 1 and not 11 or 213 or any occurrence of 1 but just 1 alone
str1.toLowerCase().contains(str2.toLowerCase())
works except it returns true for "11 contains 1" but I want it to search for 1 and not 11 or 213 or any occurrence of 1 but just 1 alone
You can loop through your string and do something like this:
for (int i = 0; i < str.length; i++)
{
if (str[i] == 'your character')
// your code ...
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MyClass {
public static void main(String args[]) {
String s = "fsdhfh11sdfsjad";
Pattern patternOne = Pattern.compile("(.)*(1)(.)*");
Pattern patternOneOne = Pattern.compile("(.)*(11)(.)*");
Matcher matchOne = patternOne.matcher(s);
Matcher matchOneOne = patternOneOne.matcher(s);
if(matchOne.find() && !matchOneOne.find()){
System.out.println("Yes");
}
}
}
You can test your String with regex like these. This works for me. I hope it could help you. :)
Greethings
Noixes