how to compare a string from url to NSutf8stringencoding return 1 or 0 with normal string @“1”

前端 未结 2 1506
悲哀的现实
悲哀的现实 2021-01-22 04:53

I need to compare a string from an url using NSutf8stringencoding in order to return 1 or 0, but it always returns 0 even if the string has value 1.



        
相关标签:
2条回答
  • 2021-01-22 05:11

    Try the following - there could be additional whitespace characters in the strResult (like carriage returns):

    if ([strResult rangeOfString:@"1"].length > 0) {
        // Do something...
    }
    
    0 讨论(0)
  • 2021-01-22 05:15

    There are probably other characters in the string.

    Use

    [strResult stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    
    0 讨论(0)
提交回复
热议问题