You need to sign in to do that
Don't have an account?
Sabrent
IgnoreCase when Key in map is a string
Is there a way to ignore the case when comparing string with a Map Key?
I tried tolowercase (), toupperCase, but for my requirement that's not a viable solution.
Any other way?
Map<string, string> colorCodes = new Map<String, String>();
string s1='RED';
string s2='BLUE';
colorCodes.put(s1.tolowercase(), 'FF0000');
colorCodes.put(s2.tolowercase(), '0000A0');
Boolean contains = colorCodes.containsKey('BluE');
System.assertEquals(contains, True); // Assertion fails
Hi raov,
As u r keeping the key in lower case, when your checking containskey convert that string also into lowercase. and then compare
This is map's property wo can not hadel it even using "tolowercase()" , "toupperCase()" methods.
Thank you everyone for your responses . Much appreciated.
I have thought of a work around. Will see how i go and post it here.
Thanks again.
I'm actually having the exact opposite problem, I'm comparing two Ids and coming up with false matches when the only difference is an upper-or-lowercase character.
Can you please let me know the workaround which you tried ? Were you able to handle this. I am in same situation like you. Waiting for your reply.
public map<string,object> convertTolowerAllkeys(Map<string,object> v){
Map<string,object> newMap = new map<string,object> ();
for(string key : v.keySet()){
newMap.put(key.toLowerCase(),v.get(key));
}
return newMap;
}
Map<String,Object> fieldMap =convertTolowerAllkeys(sobj.getPopulatedFieldsAsMap());