查找字符串位置:
NSRange range;
range = [tmpStr rangeOfString:@"ccd"];
if (range.location != NSNotFound) {
NSLog(@"found at location = %d, length = %d",range.location,range.length);
}else{
NSLog(@"Not Found");
}
TestOCC[769:c07] found at location = 2, length = 3截取字符串:
1.定义一个字符串a, 截取a 的某一个部分,复制给b, b必须是int型
NSString *a = @"1.2.30";
int b= [[a substringWithRange:NSMakeRange(4,2)] intValue];
NSLog(@"a:%@ \n",a );
NSLog(@"b:%d",b );
Output : Q[4005:207] a:1.2.30
[4005:207] b:30
本文介绍了如何在Objective-C中查找并截取特定字符串位置,包括定义字符串、使用NSRange进行截取及转换为整数类型的过程。
1万+

被折叠的 条评论
为什么被折叠?



