简体   繁体   English

如何在iPhone中删除特殊字符?

[英]How to remove the Special character in iPhone?

I have used web service and get the response in the XML format, after that i have used xml parsing for parsed contents, but i get ı: ürse kün etc., SO i want to remove that special characters and i have used NSUTF8StringEncoding and NSASCIIStringEncoding. 我使用了Web服务并以XML格式获取了响应,之后我使用xml解析了已解析的内容,但是我得到了ı:¼rsekün等,所以我想删除那些特殊字符,并且使用了NSUTF8StringEncoding和NSASCIIStringEncoding。 But it doesn't work, so please give help me out?. 但这不起作用,所以请帮帮我吗?

Either what you have is binary data, or you have a string in some encoding that's not UTF-8. 您所拥有的只是二进制数据,或者您拥有某种不是UTF-8编码的字符串。 Assuming it's the latter, you need to figure out what that encoding is, which is entirely dependent on the data, what it is, and where it came from. 假设是后者,则需要弄清楚该编码是什么,它完全取决于数据,它是什么以及它来自何处。

TESTED CODE: 100 % WORKS 测试代码: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);

OUTPUT: 输出:

    resulted String is - A±: A¼rse kA¼n

OR 要么

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);

OUTPUT: 输出:

resulted String is :A±: A1⁄4rse kA1⁄4n vijay 12344

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM