DaffodilGirl 2012-12-27 23:17 采纳率: 0%
浏览 2227
已采纳

在iPhoneSDK中删除指定HTML标签

应用中的NSString中包含HTML,我想删除< img src=..../>标签的内容。

举个例子:

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);
}
  • 写回答

1条回答 默认 最新

  • lanhailvcao 2012-12-28 00:43
    关注

    可以实现代码:

    -(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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 没输出运行不了什么问题
  • ¥20 输入import torch显示Intel MKL FATAL ERROR,系统驱动1%,: Cannot load mkl_intel_thread.dll.
  • ¥15 点云密度大则包围盒小
  • ¥15 nginx使用nfs进行服务器的数据共享
  • ¥15 C#i编程中so-ir-192编码的字符集转码UTF8问题
  • ¥15 51嵌入式入门按键小项目
  • ¥30 海外项目,如何降低Google Map接口费用?
  • ¥15 fluentmeshing
  • ¥15 手机/平板的浏览器里如何实现类似荧光笔的效果
  • ¥15 盘古气象大模型调用(python)
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部