经常出现字符串带有html标签。下面有个方法一步到位去掉HTML标签

  1. <span style="font-family: 'comic sans ms', sans-serif; color: #008080; font-size: medium;">+(NSString *)flattenHTML:(NSString *)html trimWhiteSpace:(BOOL)trim
  2. {
  3. NSScanner *theScanner = [NSScanner scannerWithString:html];
  4. NSString *text = nil;
  5. while ([theScanner isAtEnd] == NO) {
  6. // find start of tag
  7. [theScanner scanUpToString:@"<" intoString:NULL] ;
  8. // find end of tag
  9. [theScanner scanUpToString:@">" intoString:&text] ;
  10. // replace the found tag with a space
  11. //(you can filter multi-spaces out later if you wish)
  12. html = [html stringByReplacingOccurrencesOfString:
  13. [ NSString stringWithFormat:@"%@>", text]
  14. withString:@""];
  15. }
  16. return trim ? [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] : html;
  17. }
  18. </span>

调用方法:

    notification33.alertBody =[self flattenHTML:body trimWhiteSpace:YES];

 

最新文章

  1. Sublime Text 全程指引 by Lucida
  2. Spark难道比oracle性能还差?百万级数据测试性能
  3. Oracle死锁产生的原因和解决办法
  4. PAT乙级 1018. 锤子剪刀布 (20)
  5. Input gameobject vector3 c#
  6. 1.1&hellip;&hellip;什么是3G
  7. Umbraco中Document Type取名限制
  8. JS中的RegExp对象常用属性和方法
  9. 第1章 初识java----Java简介
  10. 正则表达式:reg.test is not a function
  11. Java类加载机制、类加载器和反射机制-思维导图
  12. 关于MDK下pack的定义方法
  13. Spring Aop 应用实例与设计浅析
  14. 推荐一款基于bootstrap的漂亮的前端模板—inspinia_admin
  15. 【JAVA】SWING_ 界面风格
  16. Mac OS启动服务优化高级篇
  17. 易趣:使用MongoDB创建关键业务的多数据中心应用
  18. windows服务项目的 安装 卸载 查看
  19. Linux-lvm逻辑卷管理和提示丢失pv物理卷
  20. spinnaker自动发布k8s部署应用&lt;一&gt;

热门文章

  1. Leetcode 234 Palindrome Linked List 链表
  2. Leetcode 111 Minimum Depth of Binary Tree 二叉树
  3. Android Studio no debuggable applications解决方案2
  4. Unreal Engine 4官网教程
  5. 提高D3js力导向图加载速度(转)
  6. HashMap工作原理(转载)
  7. 最详细的Linux YUM命令使用教程
  8. 如何评价微软Connect 2015?[转载]
  9. Xshell中文乱码问题
  10. A/B测试