【问题标题】:Remove specific HTML Tag in iphone SDK删除 iphone SDK 中的特定 HTML 标签
【发布时间】:2012-12-06 10:35:09
【问题描述】:

我有一个NSString,其中包含HTML 内容。但我想删除< img src=..../>标签形式的NSString。

例如

Source = < p>< a href="http://wpcore.mpf.s3.amazonaws.com/wp-content/uploads/2012/12/thumbs_img_0500.jpg">**< img class="alignleft size-full wp-image-4730" style="margin-left: 5px; margin-right: 5px;" title="thumbs_img_0500" src="http://wpcore.mpf.s3.amazonaws.com/wp-content/uploads/2012/12/thumbs_img_0500.jpg" alt="thumbs img 0500" width="120" height="120" />**< /a>The two professional level < a title="3d printing" href="http://www.makepartsfast.com/category/products/3d-printers/">3D printers< /a> that build parts in color are the Zprinter from 3D Systems and the < a href="http://www.makepartsfast.com/2012/05/3812/mcor-announces-full-3d-color-3d-printer">Iris< /a> from Mcor Technologies. Earlier this year, Mcor Technologies announced its Iris full color 3D printer at the Rapid show and recently at Euromold. The Zprinter uses ink jetted into the build powder. The Iris, however, uses a different technique for creating color parts. Dr. Conor MacCormack, CEO of Mcor, discusses this technology.</p>
< p>< a href="http://wpcore.mpf.s3.amazonaws.com/wp-content/uploads/2012/12/MacCormack-part-1.mp3">MacCormack part 1< /a>< /p>

我的 img src 标签将一直不同。 我该怎么做??

我的代码:

-(void)viewWillAppear:(BOOL)animated
{
source = [NSString stringWithFormat:@"%@",[[self.parseResults objectAtIndex:k] objectForKey:@"summary"]];

NSLog(@"%@",source);
}

【问题讨论】:

    标签: iphone html ios xcode html-parsing


    【解决方案1】:

    我通过将 HTML 转换为字符串来解决它。

    只需导入两个文件NSString+HTML.h & NSString+HTML.m 文件。

    然后调用text_str=[html_str stringByConvertingHTMLToPlainText];

    【讨论】:

      【解决方案2】:

      //像下面一样...让我知道它是否有效!!!!

      -(void)viewWillAppear:(BOOL)animated
      {
       source = [NSString stringWithFormat:@"%@",[[self.parseResults objectAtIndex:k] objectForKey:@"summary"]];
       Source=[self flattenHTML:Source];//call flattenhtml method...
       NSLog(@"%@",source);
      }
      
      
      #pragma mark ---Removing HTML Tags
      - (NSString *)flattenHTML:(NSString *)html {
      
      NSScanner *theScanner;
      NSString *text = nil;
      theScanner = [NSScanner scannerWithString:html];
      
      while ([theScanner isAtEnd] == NO) {
      
          [theScanner scanUpToString:@"<" intoString:NULL] ; 
      
          [theScanner scanUpToString:@">" intoString:&text] ;
      
      }
      html = [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
      
      return html;
      }
      

      【讨论】:

      • 我不是在告诉你你错了我的朋友,但它应该可以工作,该代码在我的每个应用程序中总是可以工作......
      猜你喜欢
      • 2019-07-28
      • 2018-11-02
      • 2018-06-21
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 2018-02-11
      • 2014-07-08
      相关资源
      最近更新 更多