• iOS 判断字符串中含有某个字符串 rangeOfString


    //判断roadTitleLab.text 是否含有qingjoin
                if([roadTitleLab.text rangeOfString:@"qingjoin"].location !=NSNotFound)//_roaldSearchText
                {
                    NSLog(@"yes");
                }
                else 
                {
                    NSLog(@"no");
                }


    在iOS8以后,还可以用下面的方法来判断是否包含某字符串:

    NSString *women = @"Hey  you are bitch ?";

    if ([women containsString:@"bitch"]) {

    NSLog(@"women 包含 bitch");

    } else {

    NSLog(@"women 不存在 bitch");

    }

    NSString *string = @"hello,fucking,you,bitch";

    //字条串是否包含有某字符串

    if ([string rangeOfString:@"fucking"].location == NSNotFound) {

    NSLog(@"string 不存在 fucking");

    } else {

    NSLog(@"string 包含 fucking");

    }

    //字条串开始包含有某字符串

    if ([string hasPrefix:@"hello"]) {

    NSLog(@"string 包含 hello");

    } else {

    NSLog(@"string 不存在 hello");

    }

    //字符串末尾有某字符串;

    if ([string hasSuffix:@"bitch"]) {

    NSLog(@"string 包含 bitch");

    } else {

    NSLog(@"string 不存在 bitch");

    }



     

    援引:https://www.cnblogs.com/qingjoin/archive/2012/12/14/2817690.html

  • 相关阅读:
    CMDB表结构设计
    mysql数据库密码
    web之提取状态码
    ELK的启动脚本
    ELK的轻量级搭建使用
    liunx安装JDK
    liunx的urandom生成随机字符
    vim快捷键
    升级系统的python程序
    Mysql的进阶小记
  • 原文地址:https://www.cnblogs.com/gaozhang12345/p/8093640.html
Copyright © 2020-2023  润新知