Objective-c 仅提取字符串中的元音
可能的重复:
Objective-C:查找字符串中的辅音
我有一个字符串,其中包含以下单词辅音和元音。如何仅将元音放入新字符串中? 我已经写了这段代码但不起作用。
<代码> NSString *str = @"辅音";
NSCharacterSet *consonantSet = [NSCharacterSet characterSetWithCharactersInString:@"bcdfghjklmnpqrstvwx"];
NSString *元音 = [[NSString alloc]stringByTrimmingCharactersInSet:consonantSet];
元音字符串的结果必须是:“ooa”。
Possible Duplicate:
Objective-C: Find consonants in string
I have a string that contains words with consonants and vowels. How put only vowels into a new string?
I have write this code but not work.
NSString *str = @"consonants";
NSCharacterSet *consonantSet = [NSCharacterSet characterSetWithCharactersInString:@"bcdfghjklmnpqrstvwx"];
NSString *vowels = [[NSString alloc]stringByTrimmingCharactersInSet:consonantSet];
Result of vowels string must be: "ooa".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然我没有尝试你的代码,但在你的情况下这行代码似乎是错误的:
你应该使用:
Though I didn't try your code but it seems like this line of code is wrong in your case:
You should be using: