In Java, how do I check if a string contains a substring (ignoring case)?
By : localghost
Date : March 29 2020, 07:55 AM
I hope this helps you . I have two Strings, str1 and str2. How do I check if str2 is contained within str1, ignoring case? code :
str1.toLowerCase().contains(str2.toLowerCase())
|
Are there any way to apply regexp in java ignoring letter case?
By : tuzkee
Date : March 29 2020, 07:55 AM
this will help Simple example: we have string "Some sample string Of Text". And I want to filter out all stop words (i.e. "some" and "of") but I don't want to change letter case of other words which should be retained. , You can use the inline case-insensitive modifier: code :
str.replaceAll ("(?i)a|the|of|some|any", "");
|
Counting occurences of substring ignoring case in JAVA
By : avm
Date : March 29 2020, 07:55 AM
This might help you You are picking up substrings that were mixed-case before - say, Div. This is not a good reason to count "div"s, though, because you would pick up parts of longer words (say, Division or Divorce). If you want a better count, you could use a simple regex to do the counting: code :
"[</]div[ />]"
Pattern countRx = Pattern.compile("[</]div[ />]", Pattern.CASE_INSENSITIVE);
Matcher m = countRx.matcher(sHtml);
int count = 0;
while (m.find()) {
count++;
}
System.out.println(count);
|
Ignoring upper case and lower case in Java
By : Gunter
Date : March 29 2020, 07:55 AM
hope this fix your issue You have to use the String method .toLowerCase() or .toUpperCase() on both the input and the string you are trying to match it with. Example: code :
public static void findPatient() {
System.out.print("Enter part of the patient name: ");
String name = sc.nextLine();
System.out.print(myPatientList.showPatients(name));
}
//the other class
ArrayList<String> patientList;
public void showPatients(String name) {
boolean match = false;
for(matchingname : patientList) {
if (matchingname.toLowerCase.contains(name.toLowerCase())) {
match = true;
}
}
}
|
Replace String ignoring case in Java
By : user3861743
Date : March 29 2020, 07:55 AM
this will help , String.replace() doesn't support regex. You need String.replaceAll(). code :
DeleteLine.replaceAll("(?i)" + Pattern.quote(Checkout), "");
|