NSString *str= @"surname";
NSMutableString *consonants = [[NSMutableString alloc] init];
NSMutableString *vowels = [[NSMutableString alloc] init];
for (int i=0; i < [str length]; i++){
if ([str characterAtIndex:i] != 'a' && [str characterAtIndex:i] != 'e' && [str characterAtIndex:i] != 'i' && [str characterAtIndex:i] != 'o' && [str characterAtIndex:i] != 'u') {
[consonants appendFormat:@"%c",[str characterAtIndex:i]];
}
else{
[vowels appendFormat:@"%c",[str characterAtIndex:i]];
}
}
if([consonants length] < 3){
[consonants appendFormat:@"%@", [vocali characterAtIndex:1]];
}
我的问题如下:
如果辅音少于 3 个,我必须将 n 元音附加到辅音字符串。
示例:
str = "mario";
辅音=“mra”;// 2 个辅音和 1 个元音
str = 狮子座;
辅音=“狮子座”;// 1 个辅音和 2 个元音
想。