如下代碼可以进行优化
/**
* 清除文本中的ie注释
* @param content
* @return
*/
public static String removeIENotes(String content) {
if(StringUtils.isNotNull(content)) {
if(content.contains("<![endif]-->")) {
content = content.substring(content.lastIndexOf("<![endif]-->")+12,content.length());
}
}
return content;
}
改良后:提共通,content是前台传过来的字符串,str是包含特殊字符的字符串。
public static String removeIENotes(String content,String str) {
if(StringUtils.isNotNull(content)) {
if(content.contains(str)) {
content = content.substring(content.lastIndexOf(str)+str.length(),content.length());
}
}
return content;
}
采用此方法在Java端insert,或者update方法中使用,具体如下例子:
String str = "<!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:RelyOnVML/> <o:AllowPNG/> </o:OfficeDocumentSettings></xml><![endif]--><!--[if gte mso 9]><xml> ...
...
...
...
...
...
...</xml><![endif]--><!--[if gte mso 10]><style> /* Style Definitions */ table.MsoNormalTable{mso-style-name:普通表格;mso-tstyle-rowband-size:0;mso-tstyle-colband-size:0;mso-style-noshow:yes;mso-style-priority:99;mso-style-parent:"";mso-padding-alt:0cm 5.4pt 0cm 5.4pt;mso-para-margin:0cm;mso-para-margin-bottom:.0001pt;mso-pagination:widow-orphan;font-size:10.5pt;mso-bidi-font-size:11.0pt;font-family:"Arial",sans-serif;mso-ascii-font-family:Arial;mso-ascii-theme-font:minor-latin;mso-hansi-font-family:Arial;mso-hansi-theme-font:minor-latin;mso-bidi-font-family:"Times New Roman";mso-bidi-theme-font:minor-bidi;mso-font-kerning:1.0pt;}</style><![endif]--><span style="mso-bidi-font-size:10.5pt;font-family:"微软雅黑",sans-serif">近年来,随着世界经济一体化的日益加深,众多跨国企业在华投资,我国大型企业也走出国门在海外投资设厂,无论是政府税务机关还是企业集团总部都不可避免地面临转让定价的问题。关联交易中的转让定价对于集团总部来说是战略行为,对于政府税务机关来说则是税收安全问题。因此,构建符合实际情况的预约定价申请事十分必要的。<span lang="EN-US"></span></span>"
aaa.setFileName(removeIENotes(str));