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輔音,我必須ñ元音附加到輔音串。追加字符串mutablestring
示例:
str =「mario」;
輔音=「mra」; // 2個輔音和1個元音
str = leo;
輔音=「leo」; // 1個輔音和2個元音
Thk。
我已經閱讀並閱讀你的問題,我只是不明白你想要 – Oliver