case-insensitive

Is there a good way to have a Map<String, ?> get and put ignoring case? [duplicate]

ε祈祈猫儿з 提交于 2019-11-27 01:55:05
This question already has an answer here: Case insensitive string as HashMap key 12 answers Is there a good way to have a Map<String, ?> get and put ignoring case? TreeMap extends Map and supports custom comparators. String provides a default case insensitive comparator. So: final Map<String, ...> map = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); The comparator does not take locale into account. Read more about it in its JavaDoc. You could use CaseInsensitiveMap from Apache's Commons Collections. Guido Would it be possible to implement your own Map overriding put/get methods ? public class

How to compare character ignoring case in primitive types

China☆狼群 提交于 2019-11-27 01:49:39
I am writing these lines of code: String name1 = fname.getText().toString(); String name2 = sname.getText().toString(); aru = 0; count1 = name1.length(); count2 = name2.length(); for (i = 0; i < count1; i++) { for (j = 0; j < count2; j++) { if (name1.charAt(i)==name2.charAt(j)) aru++; } if(aru!=0) aru++; } I want to compare the Character s of two String s ignoring the case. Simply using IgnoreCase doesn't work. Adding '65' ASCII value doesn't work either. How do I do this? Shehzad The Character class of Java API has various functions you can use. You can convert your char to lowercase at both

How to MySQL work “case insensitive” and “accent insensitive” in UTF-8

泄露秘密 提交于 2019-11-27 01:34:23
问题 I have a schema in "utf8 -- UTF-8 Unicode" as charset and a collation of "utf8_spanish_ci". All the inside tables are InnoDB with same charset and collation as mentioned. Here comes the problem: with a query like SELECT * FROM people p WHERE p.NAME LIKE '%jose%'; I get 83 result rows. I should have 84 results, because I know it. Changing where for: WHERE p.NAME LIKE '%JOSE%'; I get the exact same 83 rows. With combinations like JoSe, Jose, JOSe, etc. All the same 83 rows are reported. The

Case insensitive std::string.find()

你说的曾经没有我的故事 提交于 2019-11-27 00:36:33
I am using std::string 's find() method to test if a string is a substring of another. Now I need case insensitive version of the same thing. For string comparison I can always turn to stricmp() but there doesn't seem to be a stristr() . I have found various answers and most suggest using Boost which is not an option in my case. Additionally, I need to support std::wstring / wchar_t . Any ideas? Kirill V. Lyadvinsky You could use std::search with a custom predicate. #include <locale> #include <iostream> #include <algorithm> using namespace std; // templated version of my_equal so it could work

Case insensitive comparison of strings in shell script

别来无恙 提交于 2019-11-27 00:03:57
The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this? if you have bash str1="MATCH" str2="match" shopt -s nocasematch case "$str1" in $str2 ) echo "match";; *) echo "no match";; esac otherwise, you should tell us what shell you are using. alternative, using awk str1="MATCH" str2="match" awk -vs1="$str1" -vs2="$str2" 'BEGIN { if ( tolower(s1) == tolower(s2) ){ print "match" } }' alphaniner In Bash, you can use parameter expansion to modify a string to all lower-/upper-case

GSON: How to get a case insensitive element from Json?

烂漫一生 提交于 2019-11-26 23:20:37
问题 Code shown below works well when JSON object contains jsonKey as it was passed to the method. I wonder ... if there is a way to get a value assigned to a case insensitive representation of a key? Example: public String getOutputEventDescription(JsonElement outputEvent) throws ParserException { return retrieveString(outputEvent, DESCRIPTION); } Should work regardless whether DESCRIPTION is defined as "Description", "description" or "DeScRipTIOn" protected String retrieveString(JsonElement e,

Case insensitive sorting with Firebase orderByChild

徘徊边缘 提交于 2019-11-26 23:16:01
I’m using a FirebaseRecyclerAdapter to display a list of strings. My query uses orderByChild. The results sorts with capitalize letters first and looks like this: Item 1, Item 2, Item 3, aItem, bItem, zItem. How do I use orderByChild resulting in case insensitive sorting? You don't. Kind of. If you have data you want to sort by but there also needs to be a user representation of that data, keep two versions posts post_id_0 display_version: William sort_version: william post_id_1 display_version: Henry sort_version: henry Of course you could read in all of the data from Firebase and use

String contains - ignore case [duplicate]

跟風遠走 提交于 2019-11-26 21:47:38
This question already has an answer here: How to check if a String contains another String in a case insensitive manner in Java? 19 answers Is it possible to determine if a String str1="ABCDEFGHIJKLMNOP" contains a string pattern strptrn="gHi" ? I wanted to know if that's possible when the characters are case insensitive. If so, how? You can use org.apache.commons.lang3.StringUtils.containsIgnoreCase(CharSequence str, CharSequence searchStr); Checks if CharSequence contains a search CharSequence irrespective of case, handling null. Case-insensitivity is defined as by String.equalsIgnoreCase

Case insensitive matching in Java switch-case statement

跟風遠走 提交于 2019-11-26 21:47:12
问题 I was wondering if there is a way to perform case insensitive match in java switch case statement. the default implementation is case sensitive . Please see the example below. public class SwitchCaseTest { /** * @param args */ public static void main(String[] args) { switch ("UPPER") { case "upper" : System.out.println("true"); break; default: System.out.println("false"); break; } } } So above statement returns false as output. And i am trying make it work for case-insensitive match like

MongoDB and C#: Case insensitive search

穿精又带淫゛_ 提交于 2019-11-26 20:19:41
问题 I am using MongoDB and the C# driver for MongoDB. I recently discovered that all queries in MongoDB are case-sensitive. How can I make a case-insensitive search? I found one way to do this: Query.Matches( "FirstName", BsonRegularExpression.Create(new Regex(searchKey,RegexOptions.IgnoreCase))); 回答1: The simplest and safest way to do that is using Linq : var names = namesCollection.AsQueryable().Where(name => name.FirstName.ToLower().Contains("hamster")); As explained in the tutorial ToLower ,