Convert formatted HTML text string to NSString parts

后端 未结 1 346
野的像风
野的像风 2020-12-05 15:36

I want to decode HTML string and store it in NSString.

following is the html string for one of the response from google direction api.

teststring is          


        
相关标签:
1条回答
  • 2020-12-05 16:16

    There's a very nice NSString category that you can use, it's a part of the project MWFeedParser. More specifically, you look for the file NSString+HTML.

    The NSString+HTML category adds the following methods to the NSString Class,

    - (NSString *)stringByStrippingTags;
    - (NSString *)stringWithNewLinesAsBRs;
    - (NSString *)stringByRemovingNewLinesAndWhitespace;
    - (NSString *)stringByDecodingHTMLEntities;
    - (NSString *)stringByEncodingHTMLEntities;
    

    You could then try something like:

    NSString *summary = [[[htmlString stringByStrippingTags] stringByRemovingNewLinesAndWhitespace] stringByDecodingHTMLEntities];
    

    Hope it helps!, good luck :)

    0 讨论(0)
提交回复
热议问题