2011-09-28 79 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>「