JAva重複文字の削除

928 ワード

/**
 *       
 * @param str    
 * @param deleteStr       
 * @param keepNum     , 1  
 * @return
 */
private static String deleteStr(String str,String deleteStr,int keepNum){
	keepNum = keepNum - 1;
	String deleteStrs = "";
	if (deleteStr.equals(".") || deleteStr.equals("|")) {
		deleteStrs = "\\"+deleteStr ;
	}
	String res = "";
	String[]  strs=str.split(deleteStrs);
	if (keepNum>=strs.length -1) {
		keepNum = -1;
	}
	for(int i=0,len=strs.length;i		System.out.println(strs[i]);
		if (i==keepNum) {
			  res = res + strs[i].toString()+deleteStr;
		}else{
			res = res + strs[i].toString();
		}
	}
	return res;
}