以此作为NSString常用总结(一)的补充

      NSString* str = [NSString stringWithFormat:@"I love programing! You, come here"];
//字符串对象的大小写转换
//转换为大写
NSString* upStr = [str uppercaseString];
NSLog(@"str = %@", str);
NSLog(@"upStr = %@", upStr);
//转换为小写
NSString* lowerStr = [str lowercaseString];
NSLog(@"lowerStr = %@", lowerStr);
//转换成首字母大写
NSString* newStr = [str capitalizedString];
NSLog(@"newStr = %@", newStr); //字符串提取
//指定位置到结尾:
NSString* subStr = [str substringFromIndex:];
NSLog(@"subStr = %@", subStr);
//从指定位置提取指定长度(通过 NSRange)
subStr = [str substringWithRange: NSMakeRange(, )];
NSLog(@"subStr = %@", subStr);
//开头到指定位置
subStr = [str substringToIndex:];
NSLog(@"subStr = %@", subStr); //字符串切割(componentsSeparatedByString:)方法
//此方法根据传递的字符串进行分割,并将分割的结果以数组返回
NSArray* strArr = [str componentsSeparatedByString:@" "];
for (id str in strArr) {
NSLog(@"%@", str);
}
//拼接数组中得字符串(按指定字符串)
NSString* myStr = [strArr componentsJoinedByString:@"__"];
NSLog(@"mystr = %@", myStr);
//根据传递进来的NSCharacterSet集合进行分割(示例中包含逗号“,”和空格“ ”)
strArr = [str componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@", "]];
for (id str in strArr) {
NSLog(@"%@", str);
}
05-01 04:02