开发者

manually exclude some symbols from [NSCharacterSet letterCharacterSet] invertedSet]

The code below will remove all symbols from myString. Is there a shortest way to make some exclusive symbols (say ')from being removed while still be able to use this code?

myString = [[myString componentsSeparatedByCharactersInSet:[[NSCharacterSet letterCharacterSet] invertedSet]] componentsJoinedByString:@开发者_如何转开发""];


You will need to create a mutable copy and then make changes using the NSMutableCharacterSet.

NSMutableCharacterSet *mcs = [[[NSCharacterSet letterCharacterSet] invertedSet] mutableCopy];
[mcs removeCharactersInString:@"<characters you want excluded>"];

myString = [[myString componentsSeparatedByCharactersInSet:mcs] componentsJoinedByString:@""];

[mcs release];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜