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