美文网首页
判断字符串中某个字符最后出现的位置

判断字符串中某个字符最后出现的位置

作者: Aurora166 | 来源:发表于2016-11-01 16:26 被阅读0次

    1,从开始截取字符串到某字符最后出现的位置

    NSString *str = @"ff:ffhfffg:ff";
        str = [str substringToIndex:[str rangeOfString:@":" options:NSBackwardsSearch].location];
    

    NSStringCompareOptions 参数

    typedefNS_OPTIONS(NSUInteger, NSStringCompareOptions) {
        NSCaseInsensitiveSearch = 1,    //不区分大小写比较
        NSLiteralSearch = 2,    //逐字节比较 区分大小写
        NSBackwardsSearch = 4,    //从字符串末尾开始搜索
        NSAnchoredSearch = 8,    //搜索限制范围的字符串
        NSNumericSearch = 64,    //按照字符串里的数字为依据,算出顺序。例如 Foo2.txt < Foo7.txt < Foo25.txt
        NSDiacriticInsensitiveSearchNS_ENUM_AVAILABLE(10_5, 2_0) = 128,//忽略 "-" 符号的比较
        NSWidthInsensitiveSearchNS_ENUM_AVAILABLE(10_5, 2_0) = 256,//忽略字符串的长度,比较出结果
        NSForcedOrderingSearchNS_ENUM_AVAILABLE(10_5, 2_0) = 512,//忽略不区分大小写比较的选项,并强制返回 NSOrderedAscending 或者 NSOrderedDescending
        NSRegularExpressionSearchNS_ENUM_AVAILABLE(10_7, 3_2) = 1024   //只能应用于 rangeOfString:..., stringByReplacingOccurrencesOfString:...和 replaceOccurrencesOfString:... 方法。使用通用兼容的比较方法,如果设置此项,可以去掉 NSCaseInsensitiveSearch 和 NSAnchoredSearch
    };
    

    相关文章

      网友评论

          本文标题:判断字符串中某个字符最后出现的位置

          本文链接:https://www.haomeiwen.com/subject/ecvmuttx.html