Java写一个去掉前后关键字的方法
摘要:Java写一个去掉前后关键字的方法
java代码
package com.webkfa.test; import java.io.IOException; public class Test { public static void main(String[] args) throws IOException{ try { System.out.println(replaceBaiduTjc("mv你好啊mp3")); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 去掉前后关键词 * @param old * @return * @throws KoowoHibernateException */ public static String replaceBaiduTjc(String old)throws Exception{ if(old==null){ old=""; } String strNew=old; String[] arr={"mp3","MP3","wma","WMA","mv","MV","新专辑","试听","歌词","歌曲","音乐","新歌","电台","下载","的歌","专辑","歌"}; for (int i = 0; i < arr.length; i++) { if(strNew.endsWith(arr[i])){ int b=strNew.indexOf(arr[i]); strNew=strNew.substring(0,b); } if(strNew.startsWith(arr[i])){ int b=strNew.indexOf(arr[i]); strNew=strNew.substring(b+arr[i].length()); } } if(strNew!=null){ strNew=strNew.trim(); } return strNew; } }
相关文章
最新发布
阅读排行
热门文章
猜你喜欢