iOS 判断字符串是否含有某种字符
主要是使用3个方法
- rangeOfString 是否包含
- hasPrefix 是否在前缀包含
- hasSuffix 是否在末尾包含
如代码:
//判断字符是否包含某字符串;
NSString *staA = @"hello,JiNan,jkk";
NSRange theRange =[@"jkk" rangeOfString:staA];
NSLog(@"%d %d",theRange.location,theRange.length);
NSRange range2 = [staA rangeOfString:@"jkk"];
NSLog(@"%d %d",range2.location,range2.length);
//字条串开始包含有某字符串
if ([staA hasPrefix:@"hello"]) {
NSLog(@"has hello");
}
//字符串末尾有某字符串;
if ([staA hasSuffix:@"jkk"]) {
NSLog(@"has jkk");
}
打印结果:

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
