[英]How do I remove characters from an NSString?
我想从NSString中剥离Unicode字符(\\ u0097)。
This is simplest to remove \: 这是删除\\ u0097最简单的方法:
NSString * deGremlinedString = [theString stringByReplacingOccurrencesOfString:@"\u0097" withString:@""];
The docs for that method are right here . 该方法的文档就在这里 。
Alternatively, if the starting string is an NSMutableString, then you can use this method : 或者,如果起始字符串是NSMutableString,则可以使用以下方法 :
[theMutableString replaceOccurrencesOfString:@"\u0097" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [theMutableString length])];
Try this: 尝试这个:
NSCharacterSet* badUnicodeCharSet = [NSCharacterSet characterSetWithCharactersInString:@"\u0097"];
theString = [[theString componentsSeparatedByCharactersInSet:badUnicodeCharSet] componentsJoinedByString:@""];
I believe you have to use two backslashes to escape the backslash. 我相信您必须使用两个反斜杠来逃避反斜杠。 So @"\\\"
. 所以@"\\\"
。 I'm not positive, but I read this page that says: 我不是很肯定,但我读到此页面说:
the reason for that is the first backslash is an escape in the string literal (so you can do things like @"\\""); the second backslash is the one that makes it into the string to be parsed by NSConstantString. --boredzo 这样做的原因是第一个反斜杠是字符串文字中的转义符(因此您可以执行@“ \\”“之类的操作;第二个反斜杠是将其放入要由NSConstantString解析的字符串中的反斜杠)。
Sorry if this is wrong, but it was what I understood from the page. 抱歉,这是错误的,但这是我从页面中了解的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.