Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何将包含HTML标记的字符串显示为纯文本_Iphone_Ios - Fatal编程技术网

Iphone 如何将包含HTML标记的字符串显示为纯文本

Iphone 如何将包含HTML标记的字符串显示为纯文本,iphone,ios,Iphone,Ios,可能重复: 我正在使用google direction api在我的mapview中显示地图,它给了我HTML方向字符串,其中包含HTML标记 现在,我想以纯文本显示该字符串,我如何才能做到这一点。我的字符串如下: Head <b>southwest</b> toward <b>GH Rd</b> Exit the roundabout onto <b>GH Rd</b><div style="fon

可能重复:

我正在使用google direction api在我的mapview中显示地图,它给了我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>
向西南方向驶向GH路
从环形交叉口驶出,进入1号环形交叉口
在环形交叉路口,从第一个出口通过myonlinesearch.blogspot.com进入2号路(在600米的左侧)
在环形交叉口,从第三个出口进入CH路
在Indroda Cir,从第二个出口进入Gandhinagar Ahmedabad路/SH 71继续跟随Gandhinagar Ahmedabad路,穿过1号环形交叉口
在环形交叉路口,从第一个出口进入Sardar Patel Ring路
在Ranasan Cir,从第三个出口进入NH 8 Pass by Galaxy Restaurant(在4.3公里的左侧)
向左拐,经过Shiv Shakti Food Fort(左侧)进入银河RdPass
左转到NH59
右转穿过1号环形交叉口
右转
左转目的地在右边

您可以使用RegularExpression/谓词删除<&>之间的所有字符

但如果您的文本包含一些内容,则会将其删除

  NSRange range;
  NSString *string;
  while ((range = [string rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound){
    string=[string stringByReplacingCharactersInRange:range withString:@""];
  }
  NSLog(@"Un block string : %@",string);
NSRange范围;
NSString*字符串;
while((范围=[string rangeOfString:@“]+>”选项:NSRegularExpressionSearch])。位置!=NSNotFound){
string=[string stringByReplacingCharactersInRange:range with string:@'';
}
NSLog(@“Un块字符串:%@”,字符串);

您必须通过解析器解析文本。解析这些文本非常简单,只需扫描行并使用替换函数即可

 [yourString stringByReplacingOccurrencesOfString:@"<b>"withString:""];
[yourString stringByReplacingOccurrencesOfString:@"</b>"withString:""];
[yourString StringByReplacingOfString:@“with String:”];
[yourString StringByReplacingOfString:@“with String:”;

这会帮你解决问题。

你可以选择其中一个

-(NSString *) stringByStrippingHTML { NSRange r; NSString *s = [[self copy] autorelease]; while ((r = [s rangeOfString:@"]+>" options:NSRegularExpressionSearch]).location != NSNotFound) s = [s stringByReplacingCharactersInRange:r withString:@""]; return s; } -(NSString*)stringByStrippingHTML { NSRange; NSString*s=[[self copy]autorelease]; while((r=[s rangeOfString:@“]+>”选项:NSRegularExpressionSearch])。位置!=NSNotFound) s=[s StringByReplacingCharactersRange:r,带字符串:@”“; 返回s; }
或者最好使用NSString category从字符串中删除HTML,即“GTMNSSTRINGTMLAdditions”。

如果您还获得了其他标记,则可以使用上述答案。但这是否可以执行该标记指示的操作?回答很好,但他们仍然可以在iphone的标签中显示粗体字。请使用属性字符串。但请看这里:再次感谢,伙计,伟大的链接…thanx。。。。