标签:
1、字符串的截取
//1.截取字符串 NSString *string =@"123456d890"; NSString *str1 = [string substringToIndex:5];//截取掉下标5之前的字符串 NSLog(@"截取的值为:%@",str1); NSString *str2 = [string substringFromIndex:3];//截取掉下标3之后的字符串 NSLog(@"截取的值为:%@",str2);
2、匹配字符串
从字符串(sd是sfsfsAdfsdf)中查找(匹配)字符串(Ad)
//2.匹配字符串 NSString *string =@"sd是sfsfsAdfsdf"; NSRange range = [string rangeOfString:@"Ad"];//匹配得到的下标 NSLog(@"rang:%@",NSStringFromRange(range)); string = [string substringWithRange:range];//截取范围内的字符串 NSLog(@"截取的值为:%@",string);
3、字符串分割
根据字符串中的某个字符(A)来分割字符串
//3.分隔字符串 NSString *string =@"sdfsfsfsAdfsdf"; NSArray *array = [string componentsSeparatedByString:@"A"]; //从字符A中分隔成2个元素的数组 NSLog(@"array:%@",array); //结果是adfsfsfs和dfsdf
标签:
原文地址:http://www.cnblogs.com/somebodywx/p/5724892.html