NSString - 替换NSCharacterSet中的字符 [英] NSString - replacing characters from NSCharacterSet

查看:286
本文介绍了NSString - 替换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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆