iOS - 如何将html资源文件的整个内容读入NSString *? [英] iOS - how to read entire content of an html resource file into an NSString *?

查看:136
本文介绍了iOS - 如何将html资源文件的整个内容读入NSString *?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 html 资源文件的内容放入 NSString 对象中。这样做是否可行且可行?怎么可能呢?

I want to put the content of my html resource file into an NSString object. Is it possible and advisable to do that? How could it be done?

推荐答案

可能吗? - 是

建议? - 除非它是一个非常大的文件,为什么不呢?

Advisable? - unless it is an extremely large file, why not?

如何? - 已经有一种方法可以在 NSString - stringWithContentsOfFile:encoding:error:

How? - There is already a method to do it for you in NSString - stringWithContentsOfFile:encoding:error:.

请参阅下面的代码:

NSError* error = nil;
NSString *path = [[NSBundle mainBundle] pathForResource: @"foo" ofType: @"html"];
NSString *res = [NSString stringWithContentsOfFile: path encoding:NSUTF8StringEncoding error: &error];

这篇关于iOS - 如何将html资源文件的整个内容读入NSString *?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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