iOS__字母大小写互转

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;
    }

如果对您有帮助,帮忙点个❤️,_

iOS__字母大小写互转_第1张图片
_DSC1031.JPG

你可能感兴趣的:(iOS__字母大小写互转)