⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jmcommonutil.java

📁 梦界家园程序开发基底框架
💻 JAVA
字号:
package jm.util ;

/**
 * <H3>儐乕僥傿儕僥傿僋儔僗</H3>
 *
 * <PRE>
 *
 * 僠僃僢僋偺儐乕僥傿儕僥傿丒僋儔僗偱偡丅
 *
 * </PRE>
 *
 * @author fu_changyong(1shome)
 * @see jdk1.5.2
 * @version 1.5.2.2
 */
public class JMCommonUtil {

	/**
	 * <H3>僩儕儉.</H3>
	 *
	 * <PRE>
	 *
	 * 愭摢偲嵟屻偺嬻敀偼嶍彍偡傞丅 <br>
	 *
	 * </PRE>
	 *
	 * @param prmString
	 *            懳徾暥帤楍
	 * @return String 嬻敀傪嶍彍偟偨暥帤楍
	 */
	public static String trimSpace(String prmString) {

		// 擖椡暥帤偺null丒嬻暥帤僠僃僢僋
		if (JMCheckType.isEmpty(prmString)) {
			return prmString;
		}

		// trim
		return prmString.trim();
	}

	/**
	 * 悢抣僼僅乕儅僢僩(悢抣傪僇儞儅晅偒偵曇廤)傪峴偆
	 *
	 * @param strInput
	 *            曇廤慜悢抣
	 * @return String 曇廤屻悢抣
	 */
	public static String numFormat(String strInput) {

		boolean blnMinus = false;
		boolean blnPlus = false;
		int intStrIndex = 0;
		StringBuffer strbuffData = new StringBuffer();
		int intStrLength = 0;

		if (strInput == null || strInput.length() == 0) {
			return strInput;
		}

		if (strInput.substring(0, 1).equals("-")) {
			blnMinus = true;
			strInput = strInput.substring(1);
		} else if (strInput.substring(0, 1).equals("+")) {
			blnPlus = true;
			strInput = strInput.substring(1);
		}

		if (!JMCheckType.isNumber(strInput)) {
			return null;
		}

		intStrLength = strInput.length();
		for (; intStrIndex < intStrLength - 3; intStrIndex = intStrIndex + 3) {
			strbuffData.insert(0, strInput.substring(intStrLength - intStrIndex - 3, intStrLength
					- intStrIndex));
			strbuffData.insert(0, ",");
		}

		strbuffData.insert(0, strInput.substring(0, intStrLength - intStrIndex));

		if (blnMinus) {
			strbuffData.insert(0, "-");
		} else if (blnPlus) {
			strbuffData.insert(0, "+");
		}

		return strbuffData.toString();

	}

	/**
	 * 悢抣僼僅乕儅僢僩(悢抣傪僇儞儅晅偒偵曇廤)傪峴偆
	 *
	 * @param intInput
	 *            曇廤慜悢抣
	 * @return String 曇廤屻悢抣
	 */
	public static String numFormat(int intInput) {
		return numFormat(Integer.toString(intInput));
	}

	/**
	 * ms宯unicode傪昗弨偺unicode偵偆曄姺
	 *
	 * @param s
	 *            曄姺偟偨偄暥帤楍
	 * @return String 曄姺偟偨暥帤楍
	 */
	public static String msToStd(String s) {
		StringBuffer sb = new StringBuffer();
		char c;
		if (s == null || s.length() == 0) {
			return s;
		}
		for (int i = 0; i < s.length(); i++) {
			c = s.charAt(i);
			switch (c) {
			case 0xff3c: // FULLWIDTH REVERSE SOLIDUS ->
				c = 0x005c; // REVERSE SOLIDUS
				break;
			case 0xff5e: // FULLWIDTH TILDE ->
				c = 0x301c; // WAVE DASH
				break;
			case 0x2225: // PARALLEL TO ->
				c = 0x2016; // DOUBLE VERTICAL LINE
				break;
			case 0xff0d: // FULLWIDTH HYPHEN-MINUS ->
				c = 0x2212; // MINUS SIGN
				break;
			case 0xffe0: // FULLWIDTH CENT SIGN ->
				c = 0x00a2; // CENT SIGN
				break;
			case 0xffe1: // FULLWIDTH POUND SIGN ->
				c = 0x00a3; // POUND SIGN
				break;
			case 0xffe2: // FULLWIDTH NOT SIGN ->
				c = 0x00ac; // NOT SIGN
				break;
			}
			sb.append(c);
		}
		return new String(sb);
	}

	/**
	 * 昗弨偺unicode傪ms宯unicode偵曄姺
	 *
	 * @param s
	 *            曄姺偟偨偄暥帤楍
	 * @return String 曄姺偟偨暥帤楍
	 */
	public static String stdToMs(String s) {
		StringBuffer sb = new StringBuffer();
		char c;
		if (s == null || s.length() == 0) {
			return s;
		}
		for (int i = 0; i < s.length(); i++) {
			c = s.charAt(i);
			switch (c) {
			case 0x005c: // REVERSE SOLIDUS ->
				c = 0xff3c; // FULLWIDTH REVERSE SOLIDUS
				break;
			case 0x301c: // WAVE DASH ->
				c = 0xff5e; // FULLWIDTH TILDE
				break;
			case 0x2016: // DOUBLE VERTICAL LINE ->
				c = 0x2225; // PARALLEL TO
				break;
			case 0x2212: // MINUS SIGN ->
				c = 0xff0d; // FULLWIDTH HYPHEN-MINUS
				break;
			case 0x00a2: // CENT SIGN ->
				c = 0xffe0; // FULLWIDTH CENT SIGN
				break;
			case 0x00a3: // POUND SIGN ->
				c = 0xffe1; // FULLWIDTH POUND SIGN
				break;
			case 0x00ac: // NOT SIGN ->
				c = 0xffe2; // FULLWIDTH NOT SIGN
				break;
			}
			sb.append(c);
		}
		return new String(sb);
	}

	/**
	 * <PRE>
	 *
	 * AS400傊偺僷儔儊乕僞俀傪曇廤偡傞丅 <br>
	 *
	 * </PRE>
	 *
	 * @param strParams
	 *            懳徾暥帤楍
	 * @param intParams
	 *            懳徾暥帤楍偺僒僀僘
	 * @return String 曇廤偟偨暥帤楍
	 */
	public static String makeRPGParameter2(String[] strParams, int[] intParams) {

		// AS400傊偺僷儔儊乕僞俀
		String strReturn = "";

		try {
			// 懳徾暥帤楍偑NULL偱偼側偄丄枖偼丄懳徾暥帤楍偲懳徾暥帤楍偺僒僀僘偺屄悢偑摨偠偱偡
			if (strParams != null && intParams != null && strParams.length == intParams.length) {

				String strTemp = null;
				int size = strParams.length;

				for (int i = 0; i < size; i++) {
					//					strTemp = "";
					strTemp = isNulltoBlank(strParams[i]);
					if (intParams[i] > strTemp.length()) {
						for (int j = strTemp.length(); j < intParams[i]; j++) {
							strTemp += " ";
						}

					}
					strReturn = strReturn + strTemp;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return strReturn;
	}

	/**
	 * <PRE>
	 *
	 * 暥帤楍偺慜偺僛儘傪庢傝彍偔丅 <br>
	 *
	 * </PRE>
	 *
	 * @param strParam
	 *            懳徾暥帤楍
	 * @return String 曇廤偟偨暥帤楍
	 */
	public static String cutBeforeZero(String strParam) {

		String strReturn = "";
		long lngReturn = 0;
		if (strParam != null && !"".equals(strParam)) {
			if(strParam.length() > 0) {
				lngReturn = Long.parseLong(strParam);
				strReturn = Long.toString(lngReturn);
			}
		}
		return strReturn;
	}

	/**
	 * <PRE>
	 *
	 * NULL -> 僽儔儞僋傪曇廤偡傞丅 <br>
	 *
	 * </PRE>
	 *
	 * @param strParam
	 *            暥帤楍
	 * @return String 曇廤偟偨暥帤楍
	 */
	public static String isNulltoBlank(String strParam) {

		String strReturn = strParam;
		if (strParam == null) {
			strReturn = "";
		}

		return strReturn;
	}

	/**
	 * <PRE>
	 *
	 * 峏怴帪崗傪曇廤偡傞丅 <br>
	 * Example: strUpdatetime :61231 return :061231
	 *
	 * </PRE>
	 *
	 * @param strUpdateTime
	 *            懳徾暥帤楍
	 * @return String 曇廤偟偨暥帤楍
	 */
	public static String makeRPGParam2UpdateTime(String strUpdateTime) {

		if (strUpdateTime == null || strUpdateTime.equals("")) {
			return null;
		}

		String strResult = null;
		int timeLength = strUpdateTime.length();
		if (timeLength == 6) {
			strResult = strUpdateTime;
		} else if (timeLength > 6) {
			strResult = strUpdateTime.substring(0, 6);
		} else if (timeLength < 6) {
			strResult = strUpdateTime;
			for (int i = 0; i < (6 - timeLength); i++) {
				strResult = "0" + strResult;
			}
		}
		return strResult;
	}

	/**
	 * <H3>僩儕儉.</H3>
	 *
	 * <PRE>
	 *
	 * AS400傊偺僷儔儊乕僞俀寢壥傪庢摼偡傞丅 <br>
	 *
	 * </PRE>
	 *
	 * @param strResultString
	 *            懳徾暥帤楍
	 * @param intParams
	 *            懳徾暥帤楍偺僒僀僘
	 * @return String[] 曇廤偟偨暥帤楍
	 *
	 * @author 挌 拤摀
	 */
	public static String[] getRPGParameter2(String strResultString, int[] intParams) {

		String[] aryResultString = null;
		//懳徾暥帤楍偑NULL偱偼側偄丄枖偼丄懳徾暥帤楍偲懳徾暥帤楍偺僒僀僘偺屄悢偑摨偠偱偡
		if (strResultString != null && strResultString.length() > 0) {

			if (intParams != null && intParams.length > 0) {
				aryResultString = new String[intParams.length];
				int intStartLenth = 0;
				for (int i = 0; i < intParams.length; i++) {
					int paramsLength = intParams[i];

					if (i == 0) {
						aryResultString[i] = strResultString.substring(0, paramsLength).trim();
						intStartLenth = paramsLength;
					} else {
						if (i == intParams.length - 1) {
							aryResultString[i] = strResultString.substring(intStartLenth);
						} else {
							aryResultString[i] = strResultString.substring(intStartLenth,
									((intStartLenth + paramsLength)));
						}
						intStartLenth = paramsLength + intStartLenth;
					}
				}
			}
		}

		return aryResultString;
	}

	/**
	 *
	 * 巜掕偝傟偨寘悢偵側傞傛偆嵍偐傜巜掕偝傟偨抣傪杽傔傑偡丅
	 *
	 * @param data
	 *            懳徾暥帤楍
	 * @param fill
	 *            杽傔傞抣
	 * @param length
	 *            寘悢
	 * @return ( n * 0 ) + 僨乕僞
	 */
	public static String fillInLeft(String data, char fill, int length) {

		StringBuffer fmtData = new StringBuffer();
		int zeroSu;

		if (data == null) {

			data = "";
			zeroSu = length;

		} else if (data.getBytes().length > length) {

			zeroSu = 0;

		} else {

			zeroSu = length - data.getBytes().length;

		}

		for (int i = 0; i < zeroSu; i++)
			fmtData.append(fill);

		fmtData.append(data);
		return fmtData.toString();

	}

	/**
	 *
	 * 巜掕偝傟偨寘悢偵側傞傛偆塃偐傜巜掕偝傟偨抣傪杽傔傑偡丅
	 *
	 * @param data
	 *            懳徾暥帤楍
	 * @param fill
	 *            杽傔傞抣
	 * @param len
	 *            寘悢
	 * @return 僨乕僞 + ( fill * len )
	 */
	public static String fillInRight(String data, char fill, int len) {

		// 巜掕挿偑乽0乿偺応崌傕乽0乿傪曉偡丅
		if (len == 0)
			return data;

		// 婎杮忣曬偑乽null乿傕偟偔偼丄巜掕挿傛傝挿偄応崌偼壛岺張棟傪偟側偄
		if (data == null || data.getBytes().length > len)
			return data;

		int diffLen = len - data.getBytes().length;
		StringBuffer fmtStr = new StringBuffer(data);

		for (int i = 0; i < diffLen; i++)
			fmtStr.append(fill);

		return fmtStr.toString();

	}

	/**
	 *
	 * 僇儞儅傪彍嫀偟傑偡丅
	 *
	 * @param strInput
	 *            僇儞儅傪娷傓暥帤楍僨乕僞
	 * @return 僇儞儅傪彍嫀偝傟偨暥帤楍
	 */
	public static String removeComma(String strInput) {
		if (strInput == null) {
			return null;
		}
		if (strInput.length() < 1 || strInput.equals("")) {
			return null;
		}
		StringBuffer stbValue = new StringBuffer(strInput);

		for (int i = 0; i < stbValue.length(); i++) {
			char parts = stbValue.charAt(i);
			if (parts == ',') {
				//僇儞儅傪敪尒偟偨傜彍嫀偟丄僆僼僙僢僩傪侾偮栠偡
				stbValue = stbValue.deleteCharAt(i);
				i--;
			}
		}

		return stbValue.toString();

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -