用不可变字符串跟可变字符串做新闻网页

    //不可变字符串方法

    //新建一个字符串对象,将文件的内容读出来

    NSString *html=[NSString stringWithContentsOfFile:@"/Users/apple/Desktop/txt1.html" encoding:NSUTF8StringEncoding error:nil];

    //将文件中的标题替换成我们的标题

    NSString *html1=[html stringByReplacingOccurrencesOfString:@"{[title]}" withString:@"广西政协原副主席李达球受贿一审获刑15"];

    //新建字符串,读出新闻正文文件的内容

    NSString *count=[NSString stringWithContentsOfFile:@"/Users/apple/Desktop/count" encoding:NSUTF8StringEncoding error:nil];

    //将{[count]}替换成新闻正文内容

    NSString *html2=[html1 stringByReplacingOccurrencesOfString:@"{[count]}" withString:count];

    //加载新闻内容

    [self.mywebview loadHTMLString:html2 baseURL:nil];

    

    

    //可变字符串方法

    //新建可变字符串,读出文件内容

    NSMutableString *html3=[NSMutableString stringWithContentsOfFile:@"/Users/apple/Desktop/txt1.html" encoding:NSUTF8StringEncoding error:nil];

    //替换文件中的标题

    [html3 replaceOccurrencesOfString:@"{[title]}" withString:@"广西政协原副主席李达球受贿一审获刑15" options:NSCaseInsensitiveSearch range:NSMakeRange(0, html3.length)];

    NSString *count1=[NSString stringWithContentsOfFile:@"/Users/apple/Desktop/count" encoding:NSUTF8StringEncoding error:nil];

    //替换文件中的正文

    [html3 replaceOccurrencesOfString:@"{[count]}" withString:count1 options:NSCaseInsensitiveSearch range:NSMakeRange(0, html3.length)];

    //加载新闻内容

    [self.mywebview loadHTMLString:html3 baseURL:nil];

posted on 2014-10-13 21:56  陈丰波  阅读(114)  评论(0编辑  收藏  举报