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

发布于 2024-12-03 20:32:22 字数 139 浏览 2 评论 0原文

我已经使用了Web服务并获得了XML格式的响应,之后我使用了xml解析来解析内容,但是我得到了 ä±: ürse kün 等,所以我想删除那些特殊字符,并且我使用了 NSUTF8StringEncoding 和NSASCII字符串编码。但它不起作用,所以请帮帮我?

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. But it doesn't work, so please give help me out?.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

童话里做英雄 2024-12-10 20:32:22

您拥有的是二进制数据,或者拥有某种非 UTF-8 编码的字符串。假设是后者,您需要弄清楚该编码是什么,这完全取决于数据、它是什么以及它来自哪里。

Either what you have is binary data, or you have a string in some encoding that's not 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.

不甘平庸 2024-12-10 20:32:22

测试代码: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

TESTED CODE: 100 % WORKS

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文