字符串decode编码
NSString*codingStr = [@"我的" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
decode解码
NSString*encodingStr = [codingStr stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
判断字符串是否存在某字符
if([str1 rangeOfString:@“aaa”].location != NSNotFound) {
NSLog(@"这个字符串中有a");
}
//rangeOfString 前面的参数是要被搜索的字符串,后面的是要搜索的字符
//NSNotFound 表示请求操作的某个内容或者item没有发现,或者不存在
截取字符串
NSString*string =@"sdfsfsfsAdfsdf";
string = [string substringToIndex:7];//去掉下标7之后的字符串
NSLog(@"截取的值为:%@",string);
[string substringFromIndex:2];//去掉下标2之前的字符串
NSLog(@"截取的值为:%@",string);
匹配字符串
NSString*string =@"sdfsfsfsAdfsdf";
NSRangerange = [stringrangeOfString:@"f"];//匹配得到的下标
NSLog(@"rang:%@",NSStringFromRange(range));
string = [string substringWithRange:range];//截取范围类的字符串
NSLog(@"截取的值为:%@",string);
分隔字符串
NSString*string =@"sdfsfsfsAdfsdf";
NSArray *array = [string componentsSeparatedByString:@"A"]; //从字符A中分隔成2个元素的数组
NSLog(@"array:%@",array); //结果是adfsfsfs和dfsdf