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 = "マリオ";
子音 = "mra"; // 2 つの子音と 1 つの母音
str = レオ;
子音 = "レオ"; // 1 つの子音と 2 つの母音
なるほど。