在我的应用程序中显示文本CATextLayer
(更改字符颜色),NSMutableAttributedString
用于更改颜色,我想删除特殊字符NSMutableAttributedString
以显示弹出视图,但不知道如何删除特殊字符,以帮助解决问题
我想要这种类型的o/p
"code" to code //in NSMutableAttributedString, not in NSString
在我的应用程序中显示文本CATextLayer
(更改字符颜色),NSMutableAttributedString
用于更改颜色,我想删除特殊字符NSMutableAttributedString
以显示弹出视图,但不知道如何删除特殊字符,以帮助解决问题
我想要这种类型的o/p
"code" to code //in NSMutableAttributedString, not in NSString
to remove such characters you simply write something like this:
NSMutableString* mutableString = ...;
[mutableString replaceOccurrencesOfString:@"\"" withString:@"" options:0 range:NSMakeRange(0, mutableString.length)];
Note that symbol " is written as \" - this one is called an escape sequence. Here is a list of such special characters in C - http://msdn.microsoft.com/en-us/library/h21280bw(v=vs.80).aspx
试试这个...这可能会帮助你。
NSMutableString *unfilteredString = @"!@#$%^&*()_+|abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
NSCharacterSet *notAllowedChars = [[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"] invertedSet];
NSMutableString *resultString = [[unfilteredString componentsSeparatedByCharactersInSet:notAllowedChars] componentsJoinedByString:@""];
NSLog (@"Result: %@", resultString);
您可以尝试一下,它可能适合您的代码:
NSMutableString *mutableStrng = [NSMutableString stringWithCapacity:1000];
[mutableStrng setString:@"my name is i#pho#ne"];
[mutableStrng replaceOccurrencesOfString:@"#" withString:@"" options:0 range:NSMakeRange(0,
mutableStrng.length)];
NSMutableAttributedString *mutableAtrString = [[NSMutableAttributedString
alloc]initWithString:mutableStrng];