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