全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
JAVA过滤HTML代码和截取字符串的类(包括测试用例)import java.util.regex.Pattern; public class FunctionUtil public static void main(String args) String str = + 依据绩abc效管理体系的规定,公司决定于 + 2008年12 + 月22日 + -2009年1 + 月 23& 日期间进行2008年年度绩效考评工作, + 具体事项如下:; String str_text = Html2Text(str); System.out.println(str_text); String slice = abbreviate(str_text, 100, .); System.out.println(slice); /* * param str : * source string * param width : * strings byte width * param ellipsis : * a string added to abbreviate string bottom * return String Object * */ public static String abbreviate(String str, int width, String ellipsis) if (str = null | .equals(str) return ; int d = 0; / byte length int n = 0; / char length for (; n 256 ? d + 2 : d + 1; if (d width) break; if (d width) n = n - ellipsis.length() / 2; return str.substring(0, n 0 ? n : 0) + ellipsis; return str = str.substring(0, n); /* * param str : * source string * param width : * strings byte width * param ellipsis : * a string added to abbreviate string bottom * return String Object * */ public static String Html2Text(String inputString) String htmlStr = inputString; / 含html标签的字符串 String textStr = ; java.util.regex.Pattern p_script; java.util.regex.Matcher m_script; java.util.regex.Pattern p_style; java.util.regex.Matcher m_style; java.util.regex.Pattern p_html; java.util.regex.Matcher m_html; java.util.regex.Pattern p_html1; java.util.regex.Matcher m_html1; try String regEx_script = *?sS*?; / 定义script的正则表达式或*?sS*? / String regEx_style = *?sS*?; / 定义style的正则表达式或*?sS*? / String regEx_html = +; / 定义HTML标签的正则表达式 String regEx_html1 = +; p_script = Ppile(regEx_script, Pattern.CASE_INSENSITIVE); m_script = p_script.matcher(htmlStr); htmlStr = m_script.replaceAll(); / 过滤script标签 p_style = Ppile(regEx_style, Pattern.CASE_INSENSITIVE); m_style = p_style.matcher(htmlStr); htmlStr = m_style.replaceAll(); / 过滤style标签 p_html = Ppile(regEx_html, Pattern.CASE_INSENSITIVE); m_html = p_html.matcher(htmlStr); htmlStr = m_html.replaceAll(); / 过滤html标签 p_html1 = Ppile(regEx_html1, Pattern.CASE_INSENSITIVE); m_html1 = p_html1.matcher(htmlStr); htmlStr = m_html1.replaceAll(); / 过滤html标签
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 风电机组机械装调工变更管理知识考核试卷含答案
- 电子陶瓷薄膜成型工岗前风险评估考核试卷含答案
- 地质采样工安全操作模拟考核试卷含答案
- 服装水洗工创新应用能力考核试卷含答案
- 信用分析师岗位设备技术规程
- 工业固体废物处理处置工岗前操作安全考核试卷含答案
- 商票债权转让协议书
- 跨层级资源整合管理规定
- 华为ICT大赛考试题库(附答案)
- 第一章《三角形的证明》单元测试(能力提升)-八年级数学下册(北师大版)原卷版+解析
- NCCN宫颈癌指南(2026.V2)解读报告课件
- 2024年全国职业院校技能大赛高职组(研学旅行赛项)考试题库(含答案)
- 提升员工工作积极性的方法与策略
- 2025南海农商银行秋季校园招聘笔试备考题库附答案
- 农村办酒场合同范本
- 2025年四川省拟任县处级领导干部任职资格试题及参考答案
- 全科医学科慢性病管理规范指南
- 化工反应器设计课件
- 浙江省建筑施工安全管理规范
- 江苏省泰州市2026届化学高二第一学期期末预测试题含答案
- C大调音与音名课件
评论
0/150
提交评论