我已经使用了Web服务并以XML格式获取响应,之后我对解析的内容使用了xml解析,但我得到了ı:ürsekün等,所以我想要删除那些特殊字符而且我有使用了NSUTF8StringEncoding和NSASCIIStringEncoding。但它不起作用,所以请帮帮我吗?
答案 0 :(得分:1)
您拥有的是二进制数据,或者您的某些编码中的字符串不是UTF-8。假设它是后者,你需要弄清楚编码是什么,这完全取决于数据,它是什么,它来自何处。
答案 1 :(得分:0)
测试代码:100%工作
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
NSString *input = @"ı: ürse kün";
NSString *folded = [input stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:locale];
NSLog(@"resulted String is - %@",folded);
<强>输出:强>
resulted String is - A±: A¼rse kA¼n
或强>
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
NSString *input = @"ı: ürse kün vijay 12344";
input = [input decomposedStringWithCompatibilityMapping];
NSString *output=[input stringByTrimmingCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLKMNOPQRSTUVWXYZ0123456789"] invertedSet]];
NSString *folded = [output stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:locale];
NSLog(@"resulted String is :%@",folded);
<强>输出:强>
resulted String is :A±: A1⁄4rse kA1⁄4n vijay 12344