Case-insensitive NSString comparison

前端 未结 4 1517
梦毁少年i
梦毁少年i 2021-02-05 19:35

Using this code I am able to compare string values.

[elementName isEqualToString: @\"Response\"]

But this compares case-sensitively. Is there a

4条回答
  •  我在风中等你
    2021-02-05 19:53

    Actually isEqualToString: works with case sensitive ability. as:

    [elementName isEqualToString: @"Response"];
    

    if you want to ask for case insensitive compare then here is the code:

    You can change both comparable string to lowerCase or uppercase, and can compare as:

    NSString *tempString = @"Response";
    NSString *string1 = [elementName lowercaseString];
    NSString *string2 =  [tempString lowercaseString];
    
    //The same code changes both strings in lowerCase.
    //Now You Can compare
    
    if([string1 isEqualToString:string2])
    {
    
    //Type your code here
    
    }
    

提交回复
热议问题