0

我在给定的xml webservice中的这个&标签有问题,

     <description>I am trying to find in a timely manner: 1) 2 ea. fast unload solenoid 
    valves/Coils 2) 2 ea. Load Solenoid Valves &amp; Coils 3) 2 ea. Unload Normal
     Solenoid Valves/Coils for the following: Model # SSCA075AN Serial #0277468</description>

在使用 nsxmlparser 解析上面的 xml 之后,我得到它如下所示:

      I am trying to find in a timely manner: 1) 2 ea. fast unload solenoid valves/Coils   2) 2 ea. Load Solenoid Valves 
      &
      amp; Coils 3) 2 ea. Unload Normal Solenoid Valves/Coils for the following: Model # SSCA075AN Serial # 0277468

我必须以组合字符串的形式显示它。

4

2 回答 2

0

使用以下方法删除 html 标签:

- (NSString *)removeHTMLTags:(NSString *)str
{
   NSMutableString *htmlStr = [NSMutableString stringWithCapacity:[str length]];

   NSScanner *scanner = [NSScanner scannerWithString:str];
   NSString *tempText = nil;

   while (![scanner isAtEnd])
   {
    [scanner scanUpToString:@"<" intoString:&tempText];

    if (tempText != nil)
        [htmlStr appendString:tempText];

    [scanner scanUpToString:@">" intoString:NULL];

    if (![scanner isAtEnd])
        [scanner setScanLocation:[scanner scanLocation] + 1];

    tempText = nil;
  }
  return htmlStr;
}
于 2012-08-23T05:49:20.343 回答
0
-(NSString *) stringByStrippingHTML :(NSString*)targetStr
{
   NSRange r;
   NSString *finalStr = [targetStr copy];
   while ((r = [finalStr rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound) {
      finalStr = [finalStr stringByReplacingCharactersInRange:r withString:@""];
   }
   return finalStr;
}

参考这里 m.kocikowski 的回答 Remove HTML Tags from an NSString on the iPhone

于 2014-08-29T13:11:31.780 回答