程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> ios-顯示含有HTML標簽的字符串

ios-顯示含有HTML標簽的字符串

編輯:編程綜合問答
顯示含有HTML標簽的字符串

用谷歌API顯示地圖,然後有一些HTML方向字符串,包含了HTML標簽。

現在我想在普通文本中顯示這些字符,不知道應該怎麼實現?字符串如下:

 Head <b>southwest</b> toward <b>GH Rd</b>
    Exit the roundabout onto <b>GH Rd</b><div style="font-size:0.9em">Go through 1 roundabout</div>
    At the roundabout, take the <b>1st</b> exit onto <b>Road Number 2</b><div style="font-size:0.9em">Pass by myonlinesearch.blogspot.com (on the left in 600&nbsp;m)</div>
    At the roundabout, take the <b>3rd</b> exit onto <b>CH Rd</b>
    At <b>Indroda Cir</b>, take the <b>2nd</b> exit onto <b>Gandhinagar Ahmedabad Rd/SH 71</b><div style="font-size:0.9em">Continue to follow Gandhinagar Ahmedabad Rd</div><div style="font-size:0.9em">Go through 1 roundabout</div>
    At the roundabout, take the <b>1st</b> exit onto <b>Sardar Patel Ring Rd</b>
    At <b>Ranasan Cir</b>, take the <b>3rd</b> exit onto <b>NH 8</b><div style="font-size:0.9em">Pass by Galaxy Restaurant (on the left in 4.3&nbsp;km)</div>
    Turn <b>left</b> onto <b>Galaxy Rd</b><div style="font-size:0.9em">Pass by Shiv Shakti Food Fort (on the left)</div>
    Turn <b>left</b> onto <b>NH 59</b>
    Turn <b>right</b><div style="font-size:0.9em">Go through 1 roundabout</div>
    Turn <b>right</b>
   Turn <b>left</b><div style="font-size:0.9em">Destination will be on the right</div>

最佳回答:


可以用RegularExpression/Predicates移除< & >內所有的內容

不過如果文本也包含 <> 也會被移除

  NSRange range;
  NSString *string;
  while ((range = [string rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound){
    string=[string stringByReplacingCharactersInRange:range withString:@""];
  }
  NSLog(@"Un block string : %@",string);
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved