我有一个像...一样的字符串的数组。
"Turn left onto <b>Sri Krishna Nagar Rd</b><div class=\"google_note\">Pass by <b landmarkid=\"0x39ed58475c24020f:0x170a2130a5880d5a\" class=\"dir-landmark\">California Academy of Visual Effects</b> <div class=\"dirseg-sub\">(on the left)</div>\n</div>"
我从JSON获得的上述值。现在,我如何以下列格式获取字符串。
Turn left onto Sri Krishna Nagar Rd
Pass by California Academy of Visual Effects (on the left)
提前完成。
答案 0 :(得分:1)
使用此
NSString *str =@"Turn left onto <b>Sri Krishna Nagar Rd</b><div class=\"google_note\">Pass by <b landmarkid=\"0x39ed58475c24020f:0x170a2130a5880d5a\" class=\"dir-landmark\">California Academy of Visual Effects</b> <div class=\"dirseg-sub\">(on the left)</div>\n</div>";
str = [str stringByReplacingOccurrencesOfString:@"\\r\\n" withString:@""];
NSRange r;
while ((r = [str rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
str = [str stringByReplacingCharactersInRange:r withString:@""];
NSLog(@"%@",str);
答案 1 :(得分:0)
为什么你想要那种格式的字符串?你想在UIWebView中从JSON加载返回字符串吗?如果是,则可以通过附加“&lt;”html&gt; ..“&lt;”/ html&gt;“
来简单地调用loadHtmlString方法