NSString - 替换NSCharacterSet中的字符 [英] NSString - replacing characters from NSCharacterSet
问题描述
我有一个关于字符串编程的问题:我有一个NSCharacterSet包含所有要从我的NSString删除的字符。
我该怎么办? / p>
谢谢,
Christian
不要太担心效率,一个简单的方法是 [[myString componentsSeparatedByCharactersInSet:myCharacterSet] componentsJoinedByString:@]
。
否则,你可以通过循环中的字符,将不在集合中的字符附加到一个新的字符串。如果你这样做,记住在你的结果使用 NSMutableString
。
I gotta little question about string Programming: I have an NSCharacterSet which contains all the characters I want to remove from my NSString.
How can I do that?
Thank you, Christian
If you're not too worried about efficiency, a simple way would be [[myString componentsSeparatedByCharactersInSet:myCharacterSet] componentsJoinedByString:@""]
.
Otherwise, you could run through the characters in a loop, appending ones that weren't in the set onto a new string. If you do it that way, remember to use an NSMutableString
for your result as you're building it up.
这篇关于NSString - 替换NSCharacterSet中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!