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個元素的數組
NSLog(@"array:%@",array); //結果是adfsfsfs和dfsdf數組