Java工具类-拆分字符串组装数组,替换字符

Java工具类--拆分字符串组装数组,替换字符

Java工具类--拆分字符串组装数组,替换字符

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

蕃薯耀 2014年8月18日 14:52:43 星期一

 

/**
	 * 拆分字符串获取Ids
	 * 
	 * @param idsString id字符串
	 * @param spiltCode 拆分符号
	 * @return ids
	 * @author lqy
	 */
	@Bizlet()
	public static int[] getIdsAfterSpilt(String idsString, String spiltCode){
		List<Integer> idList = new ArrayList<Integer>();
		if(idsString == null || idsString.trim().equals("")){
			return null;
		}else{
			if(spiltCode == null || spiltCode.trim().equals("")){
				spiltCode = ",";
			}
			String[] idArray = idsString.split(spiltCode);
			if(idArray != null && idArray.length > 0){
				for (String string : idArray) {
					if(string != null && !string.trim().equals("")){
						idList.add(Integer.parseInt(string.trim()));
					}
				}
			}
		}
		if(idList != null && idList.size() > 0){
			int[] ids = new int[idList.size()]; 
			for (int j=0;j<idList.size(); j++) {
				ids[j] = idList.get(j);
			}
			return ids;
		}
		return null;
	}
	
	/**
	 * 删除字符串最后一位
	 * 
	 * @param str 字符串
	 * @return str
	 * @author lqy
	 */
	@Bizlet()
	public static String removeLastCode(String str) {
		if(str == null || str.trim().equals("")){
			str = "";
		}else{
			str = str.trim().substring(0, (str.trim().length()-1));
		}
		return str;
	}
	
	/**
	 * 替换字符
	 * 
	 * @param str 字符串
	 * @param oldCode 需要替换的原字符
	 * @param newCode 替换的新字符
	 * @return str
	 * @author lqy
	 */
	@Bizlet()
	public static String replaceCode(String str, String oldCode, String newCode) {
		if(str != null && !str.trim().equals("")){
			if(oldCode == null || oldCode.trim().equals("")){
				oldCode = " ";
			}
			if(newCode == null){
				newCode = "";
			}
			str = str.trim().replaceAll(oldCode, newCode);
		}
		return str;
	}

 

 

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

蕃薯耀 2014年8月18日 14:52:43 星期一