nbo*_*jja 23 iphone escaping objective-c html-entities
我有一个以下格式的URL字符串.
http://myserver.com/_layouts/feed.aspx?xsl=4&web=%2F&page=dda3fd10-c776-4d69-8c55-2f1c74b343e2&wp=476f174a-82df-4611-a3df-e13255d97533
我想,以取代&与&在上述网址.我的结果应该是:
http://myserver.com/_layouts/feed.aspx?xsl=4&web=%2F&page=dda3fd10-c776-4d69-8c55-2f1c74b343e2&wp=476f174a-82df-4611-a3df-e13255d97533
有人可以发给我代码来完成这项工作吗?
谢谢
Mic*_*all 114
查看我的NSString类别的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;
Run Code Online (Sandbox Code Playgroud)
Chu*_*uck 14
[urlString stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
Run Code Online (Sandbox Code Playgroud)
iPhone SDK中没有内置功能.您应该提交一个您想要该功能的错误.在普通的Mac OS X SDK中,您可以将片段作为HTML 加载到NSAttributedString中,并要求它回送普通字符串,或者使用CFXMLCreateStringByUnescapingEntities().
@interface NSString (LGAdditions)
- (NSString *) stringByUnescapingEntities;
@end
@implementation NSString (LGAdditions)
- (NSString *) stringByUnescapingEntities {
CFStringRef retvalCF = CFXMLCreateStringByUnescapingEntities(kCFAllocatorDefault, (CFStringRef)self, NULL);
return [NSMakeCollectable(retvalCF) autorelease];
}
@end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
39212 次 |
| 最近记录: |