[Cocoa]convert html to plain text
2012-06-26 12:54
309 查看
-(NSString *)convertHTMLToText:(NSString *)htmlString
{
NSString *text;
if (htmlString && [htmlString length]) {
NSAttributedString *attrString;
NSData *data = [htmlString dataUsingEncoding: NSUnicodeStringEncoding];
if (data) {
NSDictionary *encodingDict = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: NSUnicodeStringEncoding] forKey:@"CharacterEncoding"];
attrString = [[NSAttributedString alloc] initWithHTML: data documentAttributes: encodingDict];
text = [attrString string];
[attrString release];
}
}
{
NSString *text;
if (htmlString && [htmlString length]) {
NSAttributedString *attrString;
NSData *data = [htmlString dataUsingEncoding: NSUnicodeStringEncoding];
if (data) {
NSDictionary *encodingDict = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: NSUnicodeStringEncoding] forKey:@"CharacterEncoding"];
attrString = [[NSAttributedString alloc] initWithHTML: data documentAttributes: encodingDict];
text = [attrString string];
[attrString release];
}
}
相关文章推荐
- Convert HTML to Plain Text
- Convert HTML to Plain Text (把HTML文本转换成纯文本)
- Convert EXCEL TO HTML
- text/html和text/plain的区别
- HtmlToText,Html保存段落格式为文本 java版
- Howto Convert PDF files to HTML files
- 对text/plain在php与html混编的过程中出现的问题的解释
- text/html和text/plain的区别
- ABAP EXCEL文件读取函数 TEXT_CONVERT_XLS_TO_SAP的使用
- text/html和text/plain的区别
- 修改AFNetworking源文件可接收text/plain和text/html的方法
- text/html与text/plain有什么区别?
- How to enable Plain Text Password
- illegal to have multiple occurrences of 'contentType' with different values (old: [text/html; chars
- Convert HTML Table to an Array in Python
- text/html & text/plain的区别
- text/html和text/plain的区别
- Convert BBCode to HTML
- Convert Html to pdf in iOS
- Code snippet of the day : Convert Rich Text Into Plain Text.