gpt4 book ai didi

iphone - 从 NSString 中删除特殊字符

转载 作者:行者123 更新时间:2023-11-29 04:22:18 25 4
gpt4 key购买 nike

我正在做 JSON 解析。响应中有许多不同的子字符串我想删除,因为 HTML 或 ASCII 值出现在我的响应中。例如 '$quot;& 等。

我正在使用以下方法删除子字符串,但如何删除所有 ASCII 或 HTML 子字符串?

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

编辑:看这个page在 HTML 表标题下,我在响应中得到了这些符号。

最佳答案

此代码可能有助于您的查询:

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

关于iphone - 从 NSString 中删除特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12815724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com