开发者

manually exclude some symbols from [NSCharacterSet letterCharacterSet] invertedSet]

开发者 https://www.devze.com 2023-04-02 14:51 出处:网络
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?

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

精彩评论

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