iphone - 在 Objective-C 中将 & 转换为 &

标签 iphone objective-c escaping html-entities

<分区>

我有以下格式的 URL 字符串。

http://myserver.com/_layouts/feed.aspx?xsl=4&amp;web=%2F&amp;page=dda3fd10-c776-4d69-8c55-2f1c74b343e2&amp;wp=476f174a-82df-4611-a3df-e13255d97533

我想用 & 替换上面 URL 中的 &。我的结果应该是:

http://myserver.com/_layouts/feed.aspx?xsl=4&web=%2F&page=dda3fd10-c776-4d69-8c55-2f1c74b343e2&amp;wp=476f174a-82df-4611-a3df-e13255d97533

有人可以将完成此操作的代码发给我吗?

谢谢

最佳答案

查看我的 NSString category for HTML .以下是可用的方法:

// Strips HTML tags & comments, removes extra whitespace and decodes HTML character entities.
- (NSString *)stringByConvertingHTMLToPlainText;

// Decode all HTML entities using GTM.
- (NSString *)stringByDecodingHTMLEntities;

// Encode all HTML entities using GTM.
- (NSString *)stringByEncodingHTMLEntities;

// Minimal unicode encoding will only cover characters from table
// A.2.2 of http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_Special_characters
// which is what you want for a unicode encoded webpage.
- (NSString *)stringByEncodingHTMLEntities:(BOOL)isUnicode;

// Replace newlines with <br /> tags.
- (NSString *)stringWithNewLinesAsBRs;

// Remove newlines and white space from string.
- (NSString *)stringByRemovingNewLinesAndWhitespace;

关于iphone - 在 Objective-C 中将 & 转换为 &,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1067652/

相关文章:

iphone - iOS - 在 UIScrollView 上缩放 UIImageView

ios - 综合属性时实例变量的命名约定

javascript - 在 Symfony/Twig 中转义 tinyMCE javascript 输出

Ruby 停止并移动到 for 循环的下一次迭代

ios - 删除具有多个TableView的行

iphone - 我是否必须在另一个线程中运行 UIScrollView 的委托(delegate)以防止滚动期间出现性能问题?

objective-c - 如何向 XCTestCase 添加实例变量或属性?

objective-c - Objective C 合成变量下划线前缀不起作用

Bash:别名中的嵌套反引号会导致问题

iphone - UITableView 背景作为平铺图像