0

When the Webservice hit it shows the response on my textfield like this: Response i get at when i hit my web service at browser.

        catid = 38;
        created = "May 02 2013";
        "created_by" = 588;
        fulltext = "<p>

But I must explain to you how all this mistaken idea of denouncing leasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great xplorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure ?<\p>

<\p>

But I must explain to you how all this mistaken idea of denouncing leasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness.

But i want to replace <\p> <\p> with paragraph change: I want This response on my iPhone App

       catid = 38;
        created = "May 02 2013";
        "created_by" = 588;
        fulltext = "<p>

But I must explain to you how all this mistaken idea of denouncing leasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great xplorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure ?

But I must explain to you how all this mistaken idea of denouncing leasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness.

4

2 回答 2

0

试试这个功能来删除 html 标签。

    - (NSString *)flattenHTML:(NSString *)html {

        NSScanner *theScanner;
        NSString *text = nil;

        theScanner = [NSScanner scannerWithString:html];

        while ([theScanner isAtEnd] == NO) {

            // find start of tag
            [theScanner scanUpToString:@"<" intoString:NULL] ;

            // find end of tag
            [theScanner scanUpToString:@">" intoString:&text] ;

            // replace the found tag with a space
            //(you can filter multi-spaces out later if you wish)
            html = [html stringByReplacingOccurrencesOfString:
            [ NSString stringWithFormat:@"%@>", text]
                                           withString:@" "];
            html = [html stringByReplacingOccurrencesOfString:[ NSString stringWithFormat:@"&nbsp;"] withString:@" "];
        } // while //
        return html;
    }
于 2013-05-20T11:59:55.100 回答
0

不知道为什么</p>标签总是三个,因为有效的 HTML 应该成对给出标签,例如<p></p>. 但是如果你真的确定它总是三个,你可以使用 NSString 实例方法stringByReplacingOccurrencesOfString

- (NSString *)replaceThreeParagraphTags:(NSString *)html {
    return  [html stringByReplacingOccurrencesOfString:@"</p></p></p>" withString:@"\n\n"];
}

基本上我们只是替换每一个出现的三个</p>并用两个换行符替换它,\n因为您似乎希望在段落之间有一条线。

于 2013-05-20T13:04:35.550 回答