本文介绍了NSString特殊字符编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图转换一些特殊字符,例如äö code>,αμοι和其他网页。当我使用 ASIHTTPRequest 下载网页时,我得到一些代码,而不是字符本身。示例:

ä= \\\ä

μ= \\\μ

α= \\\α

Im trying to convert some special characters like ä,ö,ü,α,μ,α,ο,ι, and others from a webpage. When I download the page with the ASIHTTPRequest i get some codes instead of the character itself. Examples:
ä = \u00E4
μ = \u03BC
α = \u03B1

使用 [NSString stringWithContentsOfURL:aNSURL encoding:NSASCIIStringEncoding error:nil];
我尝试了不同的编码可用,但没有一个适用于上面的例子。例如:使用 NSUnicodeStringEncoding 我得到一些奇怪的像'中国'字符和 NSASCIIStringEncoding 我得到这些数字和字母。

This also happens if I use [NSString stringWithContentsOfURL:aNSURL encoding:NSASCIIStringEncoding error:nil];I have tried different encodings available but none of them work for the above example. For example: With the NSUnicodeStringEncoding I get some strange like 'chinese' characters and with NSASCIIStringEncoding I get these numbers&letters.

奇怪的是,如果我在网页浏览器中查看源代码,例如safari ,与正常的HTML字符实体类似:ä=& auml;

The strange thing is, if I look in the source code, in a web browser like safari, of the webpage, it's all fine, with the normal HTML character entity like: ä = ä

编码的字母回来了?



感谢


Thanks

>

对不起,我忘了提及上面的浏览器的源代码。

EDIT
Sorry, that I forgot to mention the source code of a browser above.

我刚刚在这个网站注意到:,十六进制HTML实体非常类似于我用tis代码。示例:

ä=ä

μ=&#x3bc ;

α=α

I just noticed on this site: link that the hex HTML Entity is very similar to what I have got with tis code. Examples:
ä = ä
μ = μ
α = α

你可能会看到,他们是非常相似的。只需小写, 0 的替换为 x ,开头添加 &#到结尾a ;
我只需要写一些小代码将数字和字母转换为十六进制实体,不会是一个大问题。

As you can maybe see, they are very similar. Just lowercase and the 0's are replaced with one x, and at the beginning add &#, to the end a ;.I will just have to write some small code to convert the numbers&letters to the hex entities, not going to be a big problem. Then just have to use an HTML entity convertor and done.

无论如何,非常感谢您再次帮助我。

Anyway, thanks a lot for helping me out again

Sean

推荐答案

再次尝试的代码它工作!这是他的答案的链接:

After having another try with Rob Mayoffs code it worked! Here is the link to his answer:
Converting escaped UTF8 characters back to their original form in iOS/Objective C

这篇关于NSString特殊字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 22:39