-1

在我的应用程序中显示文本CATextLayer(更改字符颜色),NSMutableAttributedString用于更改颜色,我想删除特殊字符NSMutableAttributedString以显示弹出视图,但不知道如何删除特殊字符,以帮助解决问题

我想要这种类型的o/p

"code" to code  //in NSMutableAttributedString, not in NSString
4

3 回答 3

1

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

于 2012-11-20T13:17:49.830 回答
0

试试这个...这可能会帮助你。

NSMutableString *unfilteredString = @"!@#$%^&*()_+|abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
NSCharacterSet *notAllowedChars = [[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"] invertedSet];
NSMutableString *resultString = [[unfilteredString componentsSeparatedByCharactersInSet:notAllowedChars] componentsJoinedByString:@""];
NSLog (@"Result: %@", resultString);
于 2012-11-20T13:26:18.327 回答
0

您可以尝试一下,它可能适合您的代码:

 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];
于 2012-11-20T13:38:04.430 回答