将HTML内容写入NSString并显示在iPhone上 [英] write html content to NSString and display on iphone
问题描述
我有一个webveiw,可以显示较小的html值,但有问题
i have a webveiw where i can show small html value but i have a issue
如果是这样
NSString *HTMLData =@"<h3><span style=font-family:Helvetica-Bold > <strong> Information</strong> </span></h3>";
HTMLData= [HTMLData stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
[web loadHTMLString:HTMLData baseURL:nil];
然后可以正常工作
但是如果我的NSString有换行符,可以说
but if my NSString has a break line lets say
NSString *HTMLData =@"<h3><span style=font-family:Helvetica-Bold >
<strong> Information</strong>
</span></h3>";
然后我遇到错误了如何避免此错误??? 我的错误缺少终止符
then i am getting error how to avoid this error??? my error is missing terminator charcter
推荐答案
要将多行中的长NSString分隔开,需要在每行的末尾加上双引号:
To break long NSStrings across multiple lines, you need to put double quotes at the end and beginning of each line:
NSString *HTMLData =@"<h3><span style=font-family:Helvetica-Bold >"
"<strong> Information</strong>"
"</span></h3>";
修改:
NSMutableString的示例:
An example with NSMutableString:
NSMutableString *HTMLData = [[NSMutableString alloc] initWithCapacity:100];
[HTMLData appendString:@"<h3><span style=font-family:Helvetica-Bold >"];
[HTMLData appendString:@"<strong> Information</strong>"];
[HTMLData appendString:@"</span></h3>"];
//more appends...
//do something with HTMLData here
[HTMLData release];
initWithCapacity只是告诉您最初要分配多少个字符(这不是限制).
The initWithCapacity just tells how many characters to allocate space for initially (it's not a limit).
NSMutableString也具有appendFormat:
方法,其作用类似于stringWithFormat:
.
NSMutableString also has the appendFormat:
method which works like stringWithFormat:
.
这篇关于将HTML内容写入NSString并显示在iPhone上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!