1.截取字符串
NSString*string =@"sdfsfsfsAdfsdf";
string = [string?substringToIndex:7];//截取下標(biāo)7之前的字符串
NSLog(@"截取的值為:%@",string);
[string?substringFromIndex:2];//截取下標(biāo)2之后的字符串
NSLog(@"截取的值為:%@",string);
2.匹配字符串
NSString*string =@"sdfsfsfsAdfsdf";
NSRangerange = [stringrangeOfString:@"f"];//匹配得到的下標(biāo)
NSLog(@"rang:%@",NSStringFromRange(range));
string = [string?substringWithRange:range];//截取范圍類的字符串
NSLog(@"截取的值為:%@",string);
3.分隔字符串
NSString*string =@"sdfsfsfsAdfsdf";
NSArray?*array = [string?componentsSeparatedByString:@"A"]; //從字符A中分隔成2個(gè)元素的數(shù)組
NSLog(@"array:%@",array); //結(jié)果是adfsfsfs和dfsdf