2011-09-28 46 views
0

我有数组具有字符串如..问题检索串

"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.Now了,我怎么可以得到如下格式的字符串。

Turn left onto Sri Krishna Nagar Rd 
Pass by California Academy of Visual Effects (on the left) 

Thanx提前。

回答

1

使用此

NSString *str [email protected]"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); 
+0

@ Narayana..It已经解决了我的问题,但我不'不知道while循环做什么..尤其是<[^>] +>。Thnx的帮助 – iCoder4777

0

为什么你想要那种格式的字符串?你想从UIWebView中的JSON加载返回字符串吗?如果是的话,那么你可以简单地调用loadHtmlString方法通过将“< ”HTML> ..“ < ”/ HTML>“