![JAVA过滤HTML代码和截取字符串的类(包括测试用例)_第1页](http://file3.renrendoc.com/fileroot_temp3/2022-1/10/c282563a-866f-4460-9c9b-34b75bfdf303/c282563a-866f-4460-9c9b-34b75bfdf3031.gif)
![JAVA过滤HTML代码和截取字符串的类(包括测试用例)_第2页](http://file3.renrendoc.com/fileroot_temp3/2022-1/10/c282563a-866f-4460-9c9b-34b75bfdf303/c282563a-866f-4460-9c9b-34b75bfdf3032.gif)
![JAVA过滤HTML代码和截取字符串的类(包括测试用例)_第3页](http://file3.renrendoc.com/fileroot_temp3/2022-1/10/c282563a-866f-4460-9c9b-34b75bfdf303/c282563a-866f-4460-9c9b-34b75bfdf3033.gif)
![JAVA过滤HTML代码和截取字符串的类(包括测试用例)_第4页](http://file3.renrendoc.com/fileroot_temp3/2022-1/10/c282563a-866f-4460-9c9b-34b75bfdf303/c282563a-866f-4460-9c9b-34b75bfdf3034.gif)
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、JAVA过滤HTML代码和截取字符串的类(包括测试用例)import java.util.regex.Pattern;public class FunctionUtil public static void main(String args) String str = "<p><font size="2"><span style="mce_style="font-size: 10.5pt">"+ "依据绩abc效管理体系的规定,公司决定于</span><span
2、 style=" mce_style="font-size: 10.5pt">"+ "2008</span><span style=" mce_style="font-size: 10.5pt">年</span><span style=" "+ "mce_style="font-size: 10.5pt">12</span><span style=" mce_style="f
3、ont-size: 10.5pt">"+ "月</span><span style=" mce_style="font-size: 10.5pt">22</span><span style=" "+ "mce_style="font-size: 10.5pt">日</span><span style=" mce_style="font-size: 10.5pt">"+
4、""-2009</span><span style=" mce_style="font-size: 10.5pt">年</span><span style=" "+ "mce_style="font-size: 10.5pt">1</span><span style=" mce_style="font-size: 10.5pt">"+ "月</span><s
5、pan style=" mce_style="font-size: 10.5pt"> 23& </span><span style=" "+ "mce_style="font-size: 10.5pt">日期间进行</span><span style=" mce_style="font-size: "+ "10.5pt">2008</span><span style="mce_
6、style="font-size: 10.5pt">年年度绩效考评工作,"+ "具体事项如下:</span></font></p>"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 :
7、* string's byte width* param ellipsis :* a string added to abbreviate string bottom* <a href=" class="referer" target="_blank">return</a> String Object*/public static String abbreviate(String str, int width, String ellipsis) if (str = null | "".equa
8、ls(str) return ""int d = 0; / byte lengthint n = 0; / char lengthfor (; n < str.length(); n+) d = (int) str.charAt(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.
9、substring(0, n);/* param str :* source string* param width :* string's byte width* param ellipsis :* a string added to abbreviate string bottom * <a href=" class="referer" target="_blank">return</a> String Object*/public static String Html2Text(String inputSt
10、ring) 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_htm
11、l1;java.util.regex.Matcher m_html1;try String regEx_script ="<s*?script>*?>sS*?<s*?/s*?scripts*?>" / 定义script的正则表达式或<script>*?>sS*?</script> / String regEx_style ="<s*?style>*?>sS*?<s*?/s*?styles*?>" / 定义style的正则表达式或<style>*?>
12、sS*?</style>/ 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_sty
13、le,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
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度办事处知识产权专利实施许可与授权合同
- 家装项目监管合同
- 二零二五年度办公室清洁与员工健康关怀合同
- 农产品销售居间合同委托书
- 有保证人借款合同
- 全新借钱的合同
- 制造业自动化技术指南
- 医院技术合作协议
- 工程建设项目招标代理协议书
- 商标权转让合同
- C++反汇编与逆向分析技术揭秘(第2版)
- 实验动物饲养人员岗位竞聘演讲范文汇报报告范文
- 商业地产市场竞品楼盘市场调研表格
- GB/T 709-2019热轧钢板和钢带的尺寸、外形、重量及允许偏差
- GB/T 14177-2003林业机械便携式割灌机和割草机试验方法
- FZ/T 54007-2019锦纶6弹力丝
- DB11-T 291-2022日光温室建造规范
- 外贸业务员面试试卷
- 纪检知识答题测试题及答案
- 人教版八年级人文地理下册知识点整理(2021版)
- 道教系统诸神仙位宝诰全谱
评论
0/150
提交评论