简体   繁体   English

从NSString删除特殊字符

[英]Remove special characters from NSString

I am doing JSON parsing. 我正在执行JSON解析。 There are many different substrings in response which I want to remove, because HTML or ASCII values comes in my response. 我想删除响应中有许多不同的子字符串,因为响应中包含HTML或ASCII值。 Like ' 喜欢' or $quot; $quot; or & etc. &等。

I am using following method for remove substring, but how I can remove all ASCII or HTML substrings ? 我正在使用以下方法删除子字符串,但是如何删除所有ASCII或HTML子字符串?

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

Edit: Look this page under the HTML Table Heading, I got these symbols in my response. 编辑:在HTML表格标题下查看此页面 ,我在响应中得到了这些符号。

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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