string - What is the correct alternative to Java's equalsIgnoreCase? -
there lots , lots of examples on why , when java.lang.string.equalsignorecase
fail because of wrong utilize of locale.
but did not find examples of right way. unlike java.lang.string.touppercase
there no version locale parameter. converting both strings upper or lower case seem wasteful. when working on application doing lot of comparisons.
what right way create ignore case string comparison, taking both locale , performance consideration?
a possible alternative might abusing regex. quite performance-intensive dynamically changing strings, if comparing against constants could alternative:
matcher matcher = pattern.compile("^" + myotherstring + "$", pattern.case_insensitive | pattern.literal | pattern.unicode_case).matcher(); if (matcher.matches(mystring)) { // ... }
this anchors string want compare against, specifies unicode-aware case-insensitive matching of literal string.
java string localization string-comparison
No comments:
Post a Comment