[java]去零(不带小数点)



/**
	 * 功能说明
	 * 去零(不带小数点)
	 * @param oldStr   原字符串
	 * @param LR       l-去前导零  r-去后导零  lr-去前后零
	 * @throws IOException
	 * 

* 例如:
* 使用例子说明 * String a = Sundry.trimZero("0000012345000","l") * String b = Sundry.trimZero("0000012345000","lr") *

*/ public static String trimZero(String oldStr,String LR)throws IOException{ String tmpStr1=""; if(LR.equals("l") || LR.equals("L")){ while(true){ if(oldStr.length()==1) break; tmpStr1=oldStr.substring(0, 1); if (!tmpStr1.equals("0")) break; oldStr=oldStr.substring(1, oldStr.length()); } } if(LR.equals("r") || LR.equals("R")){ while(true){ if(oldStr.length()==1) break; tmpStr1=oldStr.substring(oldStr.length()-1, oldStr.length()); if (!tmpStr1.equals("0")) break; oldStr=oldStr.substring(0, oldStr.length()-1); } } if(LR.equals("lr") || LR.equals("LR")){ oldStr=trimZero(oldStr,"l"); oldStr=trimZero(oldStr,"r"); } return oldStr; }


你可能感兴趣的:(Java,java开发)