URL编码和HTML编码NSStrings [英] URL-encoding and HTML-encoding NSStrings

查看:141
本文介绍了URL编码和HTML编码NSStrings的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

他们是一种编码/解码HTML和URL的方法(在Xcode中,使用Objective-C)?

  [NSString stringWithContentsOfFile:<#(NSString *)path#>编码:其中#(NSStringEncoding)ENC#>错误:<#(NSError **)错误#>] 

工作我的预期我以为会转换特殊字符,如<到等效的HTML实体,即<在这种情况下



以下是对与此主题相关的w3school链接(一般)的引用:



< a href =http://www.w3schools.com/tags/ref_urlencode.asp =nofollow noreferrer> HTML URL编码参考



HTML实体参考



感谢预期。

解决方案

使用给定的编码返回接收者的表示,以确定转换接收器所需的百分比转义一个合法的URL字符串。

   - (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding 



返回一个新的字符串,通过在接收方中替换所有百分号转义,匹配的字符由给定的编码确定。

   - (NSString *)stringByReplacingPercentEscapes usingEncoding:(NSStringEncoding)encoding 


Is their a method to encode/decode HTML and URL (in Xcode, using Objective-C)?

[NSString stringWithContentsOfFile:<#(NSString *)path#> encoding:<#(NSStringEncoding)enc#> error:<#(NSError **)error#>]

This doesn't seem to work how i expected. I thought it will convert special characters like "<" to equivalent HTML entities i.e. "<" in this case.

Here's a reference to the w3school link related to this topic (general):

HTML URL Encoding Reference

HTML Entities Reference

Thanking in anticipation.

解决方案

Returns a representation of the receiver using a given encoding to determine the percent escapes necessary to convert the receiver into a legal URL string.

- (NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding

and

Returns a new string made by replacing in the receiver all percent escapes with the matching characters as determined by a given encoding.

- (NSString *)stringByReplacingPercentEscapesUsingEncoding:(NSStringEncoding)encoding

这篇关于URL编码和HTML编码NSStrings的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆