用到老是要去找,还是记下来方便!!!
1.截取字符串
NSString*string [email protected]"tate_zwt";
string = [string substringToIndex:3];//截取下标7之后的字符串
WTLog(@"截取的值为:%@",string);
2.匹配字符串
NSString*string [email protected]"tate_zwt";
NSRangerange = [stringrangeOfString:@"t"];//匹配得到的下标
WTLog(@"rang:%@",NSStringFromRange(range));
string = [string substringWithRange:range];//截取范围类的字符串
WTLog(@"截取的值为:%@",string);
3.分隔字符串
NSString*string [email protected]"tate_zwt_zwt";
NSArray *array = [string componentsSeparatedByString:@"_"]; //从字符A中分隔成2个元素的数组
WTLog(@"array:%@",array); //结果是3个对象分别是:tate、zwt、zwt
时间: 2024-10-20 23:38:46