zoukankan      html  css  js  c++  java
  • oc温习五:字符串

    /**
         substringFromIndex:
         --从第from位数 开始截取字符串
         */
        NSString *str = @"asdfghjkzxcbnm";
        NSString *subFromStr = [str substringFromIndex:4];
        NSLog(@"-----subFromeStr=%@-----", subFromStr);  //ghjkzxcbnm
        
        /**
         substringToIndex:
         -- 字符串截取到第to位
         */
        NSString *subToStr = [str substringToIndex:6];
        NSLog(@"-----subToStr=%@-----", subToStr); //asdfgh
        
        /**
         substringWithRange:
         -- 截取range的范围的字符串
         */
        NSString *subRangeStr = [str substringWithRange:NSMakeRange(3, 4)];
        NSLog(@"-----subRangeStr=%@-----", subRangeStr);  //fghj
        
        /**
         - (NSComparisonResult)compare:(NSString *)string;
         - (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask;
         - (NSComparisonResult)compare:(NSString *)string options:(NSStringCompareOptions)mask range:(NSRange)rangeOfReceiverToCompare;
         -- 字符串的比较大小
         */
        NSString *compareStr = @"fgrt";
        NSLog(@"-----compare=%ld-----",[str compare:compareStr]);//-1
        
        /**
         caseInsensitiveCompare
         -- 比较字母,忽略大小写
         */
        NSString *caseInsStr = @"adE";
        NSLog(@"-----compare=%ld-----", [str compare:caseInsStr]);//1
        
        /**
         localizedCompare
         -- 按照 汉字 拼音字母排序
         */
        NSString *name1 = @"安";
        
        NSLog(@"-----compare=%ld-----",[name1 localizedCompare:@"微微"]);  //-1
        
        /**
         localizedStandardCompare:
         -- added in 10.6,比较字符串不管是汉子还是字符串
         */
        NSLog(@"-----comare111==%ld-----", [str localizedStandardCompare:name1]);  // 1
        
        /**
         isEqualToString
         -- 比较两个字符串是否相等
         */
        
        /**
         hasPrefix:
         -- 是否包含了前缀 str
         */
        NSLog(@"-----hasPrefix=%d-----", [str hasPrefix:@"as"]);
        
        /**
         hasSuffix:
         -- 结束字符串中是否包含 str 字符串
         */
        NSLog(@"-----hasSuffix=%d-----", [str hasSuffix:@"bnm"]);
        
        /**
         commonPrefixWithString: options:
         -- 找与之开头相同的字符,返回相同开头的字符串
         */
        NSString *commonPrdfixStr = [str commonPrefixWithString:@"as" options:NSCaseInsensitiveSearch];
        NSLog(@"-----commonPrdfixStr=%@-----", commonPrdfixStr);
        
        /**
         containsString:
         -- 是否包含了某字符串 区分大小写
         */
        NSLog(@"-----containsString=%d-----", [str containsString:@"Fg"]);  //0
        
        /**
         localizedCaseInsensitiveContainsString:
         -- 是否包含了某字符串 不区分大小写
         */
        NSLog(@"-----localizedCaseInsensitiveContainsString=%ld-----", [str localizedStandardCompare:@"Fg"]);
    
  • 相关阅读:
    删除sql注入
    查询所有数据库,数据集
    删除SQL注入的一些方法总结
    需求变更
    ASP/SQL 注入天书
    js元素闪动效果
    JS 运行、复制、另存为 代码。
    判断是否是手机访问及大致手机网页格式
    过滤资源地址
    Tomcat目录介绍以及运行时寻找class的顺序
  • 原文地址:https://www.cnblogs.com/lyz0925/p/7211244.html
Copyright © 2011-2022 走看看