传入一个字符串,已知字符串只由字母组成,将其中的大写字母转换为小写,小写转换为大写,返回转换后的字符串 如传入:@"GOODgoodSTUDY",返回@"goodGOODstudy" */ - (NSString *)upperExchangeLower:(NSString *)str { NSMutableString *str1=[[NSMutableString alloc] initWithString:str]; for (NSUInteger i=0; i<str1.length; i++) { unichar ch=[str1 characterAtIndex:i]; if (ch>='a'&&ch<='z') { [str1 replaceCharactersInRange:NSMakeRange(i, 1) withString:[NSString stringWithFormat:@"%c",ch-32]]; } else if(ch>='A'&&ch<='Z') { [str1 replaceCharactersInRange:NSMakeRange(i, 1) withString:[NSString stringWithFormat:@"%c",ch+32]]; } } return str1; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-07 04:50:17