iOS改变字母的大小写

时间:2022-08-15 09:27:25

使用lowercaseString,uppercaseString

-(void)test{

NSString * str = @"person";

NSString * str1 = [str lowercaseString];

NSString * str2 = [str uppercaseString];

NSLog(@"%@,%@",str1,str2);

 

NSString * text = @"Hello World";

text = [text stringByReplacingCharactersInRange:NSMakeRange(0, 1) withString:[[text substringToIndex:1]lowercaseString ]];

NSLog(@"text:%@",text);

}

打印结果:

2016-07-29 11:49:47.455 改变字母大小写[1058:50425] str1:person

2016-07-29 11:49:47.455 改变字母大小写[1058:50425] str2:PERSON

2016-07-29 11:49:47.456 改变字母大小写[1058:50425] text:hello World