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

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

大家好,又见面了,我是你们的朋友全栈君。

代码语言:javascript代码运行次数:0运行复制//判断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”);

}

代码语言:javascript代码运行次数:0运行复制援引:https://www.cnblogs.com/qingjoin/archive/2012/12/14/2817690.html

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/154818.html原文链接:https://javaforall.cn

相关文章

🪶
香港电话卡怎么选?上台卡&储值卡对比!
365bet官网多少

香港电话卡怎么选?上台卡&储值卡对比!

07-18 👀 5134
🪶
亿华考勤管理软件
365bet官网多少

亿华考勤管理软件

07-06 👀 6262