Cat Learn iOS Remove HTML tags from the server return data, remove the specified string, replace the string

Source: Internet
Author: User

Cat Share, must boutique

Original articles, welcome reprint. Reprint Please specify: Sanayu's Blog
Address: http://blog.csdn.net/u013357243

One: The problem

, the data returned by the server has a large string of HTML, but we only use strings, because do not want to trouble background modification data .... (meow is very considerate of others) and then find a way to solve it.

In fact, there are many ways to solve the problem. For example, the use of string interception method to range, and then according to the location to get inside the desired east. GA, think of all collapsed.
And with regular expressions and so on ... Regular expression, to tell the truth this thing in addition to interview when said say and study used to do the project has never written himself, pass, so online search learning, got a way to share to everyone.

Two: Solve
//Remove HTML tags-(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:[NSStringstringwithformat:@"%@>", text] withstring:@""]; }returnhtml;}

Well, that's the way it is, and he's going to replace the label method (with < >) directly with the @ "" Space and return it.

Cat Learn iOS Remove HTML tags from the server return data, remove the specified string, replace the string

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.