简体   繁体   中英

Remove special characters from NSString

I am doing JSON parsing. There are many different substrings in response which I want to remove, because HTML or ASCII values comes in my response. Like ' or $quot; or & etc.

I am using following method for remove substring, but how I can remove all ASCII or HTML substrings ?

NSString *strTe=[strippedString
         stringByReplacingOccurrencesOfString:@"&#39 ;" withString:@""];

Edit: Look this page under the HTML Table Heading, I got these symbols in my response.

This code may help your query :

- (NSString *)flattenHTML:(NSString *)html 
{    
    NSScanner *theScanner;
    NSString *text = nil;
    theScanner = [NSScanner scannerWithString:html];

    while ([theScanner isAtEnd] == NO) 
   {    
        [theScanner scanUpToString:@"<" intoString:NULL] ; 
        [theScanner scanUpToString:@">" intoString:&text] ;
        html = [html stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%@>", text] withString:@""];
   }

   html = [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

   return html;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM