OC字母大小写互转
- 大写转小写
-(NSString *)stringToLower:(NSString *)str{
for (NSInteger i = 0; i < str.length; i++) {
if ([str characterAtIndex:i] >= 'A' & [str characterAtIndex:i] <= 'Z') {
char temp = [str characterAtIndex:i]+32;
NSRange range = NSMakeRange(i, 1);
str = [str stringByReplacingCharactersInRange:range withString:[NSString stringWithFormat:@"%c",temp]];
}
}
return str;
}
- 小写转大写
-(NSString *)stringToUpper:(NSString *)str{
for (NSInteger i = 0; i < str.length; i++) {
if ([str characterAtIndex:i] >= 'a' & [str characterAtIndex:i] <= 'z') {
char temp = [str characterAtIndex:i] - 32;
NSRange range = NSMakeRange(i, 1);
str = [str stringByReplacingCharactersInRange:range withString:[NSString stringWithFormat:@"%c",temp]];
}
}
return str;
}
如果对您有帮助,帮忙点个❤️,_