【发布时间】:2011-10-24 15:16:56
【问题描述】:
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 个元音
想。
【问题讨论】:
-
我已经阅读并阅读了您的问题,但我只是不明白您想要什么
标签: iphone objective-c nsmutablestring