1.截取字符串
NSString*string =@"sdfsfsfsAdfsdf";
string = [string substringToIndex:6];//截取下标6之后的字符串
NSLog(@"截取的值为:%@",string);
[string substringFromIndex:3];//截取下标3之前的字符串
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个元素的数组
NSString*string =@"sdfsfsfsAdfsdf";
string = [string substringToIndex:6];//截取下标6之后的字符串
NSLog(@"截取的值为:%@",string);
[string substringFromIndex:3];//截取下标3之前的字符串
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
4. 替换方法
NSString *string = @"This is a const string";
NSString *string11 = [string stringByReplacingOccurrencesOfString:@"is" withString:@"are"];
这个将is全部替换,如何选择性替换is,比如第二个is