首页 > Java

Java写一个去掉前后关键字的方法

发表于2014-09-05 11:25:01| --次阅读| 来源webkfa| 作者小豆豆

摘要: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;
	}
}

相关文章

猜你喜欢

学到老在线代码浏览器 关闭浏览
友情链接: hao123 360导航 搜狗网址导航 114啦网址导航 博客大全
Copyright © 1999-2014, WEBKFA.COM, All Rights Reserved  京ICP备14034497号-1