iOS之字符串截取、iOS 字符串替换、iOS字符串分隔、iOS之字符串匹配、截取字符串、匹配字符串、分隔字符串
1.iOS 字符串截取
NSString*string =@"123456d890";
NSString*str1 = [string substringToIndex:5];//截取掉下标5之前的字符串
NSLog(@"截取的值为:%@",str1);
NSString*str2 = [string substringFromIndex:3];//截取掉下标3之后的字符串
NSLog(@"截取的值为:%@",str2);
2.iOS 字符串替换
NSString*strUrl = [urlString stringByReplacingOccurrencesOfString:@";"withString:@"."];
ios 根据字符串下坐标替换某段字符
NSString*idCard = [Str stringByReplacingCharactersInRange:NSMakeRange(2,6) withString:@"XXXXXXXXX"];
3.iOS 字符串分隔,分隔字符串
NSString*string =@"1234567";
NSArray*array = [string componentsSeparatedByString:@"4"];//从字符A中分隔成2个元素的数组
NSLog(@"array:%@",array);//结果是123和567
5.iOS 字符串匹配,匹配字符串
NSString*string =@"1234567";
NSRangerange = [string rangeOfString:@"45"];//匹配得到的下标
NSLog(@"rang:%@",NSStringFromRange(range));
string = [string substringWithRange:range];//截取范围内的字符串
NSLog(@"截取的值为:%@",string);
网友评论