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]];
}
My problem is the follow:
if there are less of 3 consonant, I must append n vowels to consonants string.
Examples:
str = "mario";
consonants = "mra"; // 2 consonants and 1 vowels
str = leo;
consonants = "leo"; // 1 consonant and 2 vowels
页: 1