用到老是要去找,还是记下来方便!!!
1.截取字符串
NSString*string =@"tate_zwt";
string = [string substringToIndex:3];//截取下标7之后的字符串
WTLog(@"截取的值为:%@",string);
2.匹配字符串
NSString*string =@"tate_zwt";
NSRangerange = [stringrangeOfString:@"t"];//匹配得到的下标
WTLog(@"rang:%@",NSStringFromRange(range));
string = [string substringWithRange:range];//截取范围类的字符串
WTLog(@"截取的值为:%@",string);
3.分隔字符串
NSString*string =@"tate_zwt_zwt";
NSArray *array = [string componentsSeparatedByString:@"_"]; //从字符A中分隔成2个元素的数组
WTLog(@"array:%@",array); //结果是3个对象分别是:tate、zwt、zwt
4.拼接字符串
NSMutableString *append = [[NSMutableString alloc]init];
[append appendString:@"我是"];
[append appendString:@"tate-zwt"];
WTLog(@"%@",append);//输出:我是tate-zwt
5.替换字符串
NSString *content = @"我是  tate-zwt";
content = [content stringByReplacingOccurrencesOfString:@" " withString:@""];
WTLog(@"%@",content);//输出:我是tate-zwt