字符串的截取与大小写改变
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *str0 = @"中文my name is xuanyusong";
//截取字符串起始点到index为4之间的内容
NSString * to = [str0 substringToIndex:4];
NSLog(@"to = %@",to);
//截取字符index为2 到结尾之间的内容
NSString * from = [str0 substringFromIndex:2];
NSLog(@"from = %@",from);
//设置截取字符串的范围
//从第二位到第十位
NSRange rang = NSMakeRange(2, 10);
NSString * strRang = [str0 substringWithRange:rang];
NSLog(@"rang = %@",strRang);
//设置字符串首字母大写
NSLog(@"str0首字母大写:%@",[str0 capitalizedString]);
//设置字符串全部内容为大写
NSLog(@"str0大写:%@",[str0 uppercaseString]);
//设置字符全部内容为小写
NSLog(@"str0小写:%@",[str0 lowercaseString]);
} |
|