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
4. //截取方法
NSString*str6 =@"www.tedu.cn";
NSString*str7 = [str6substringToIndex:3];//截取头
NSLog(@"%@", str7);
NSString*str8 = [str6substringFromIndex:9];//截取尾
NSLog(@"%@", str8);
NSString*str9 = [str6substringWithRange:NSMakeRange(4,4)];
NSLog(@"%@", str9);
//拼接方法
NSString*str10 =@"Hello ";
NSString*str11 =@"world!";
NSString*str12 = [[NSStringalloc]initWithFormat:@"%@%@", str10, str11];//初始化拼接
NSLog(@"%@", str12);
NSString*str13 = [str10stringByAppendingString:str11];//追加拼接
NSLog(@"%@", str13);
NSString*str14 = [str10stringByAppendingFormat:@"%@,%d", str11, a];//格式化拼接
NSLog(@"%@", str14);
//替换方法
NSString*str15 =@"www.tarena.com.cn";
NSString*str16 = [str15stringByReplacingCharactersInRange:NSMakeRange(4,10)withString:@"tedu"];
NSLog(@"%@", str16);