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

📄 jmutility.java

📁 梦界家园程序开发基底框架
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	        boolean loopflg = true;
	        while (loopflg) {
	            toindex = input.indexOf(splitor, fromindex);
	            if (toindex != -1) {
	                ary.add(input.substring(fromindex, toindex));
	            } else {
	                ary.add(input.substring(fromindex));
	                loopflg = false;
	            }
	            fromindex = toindex + splitor.length();
	        }
	        return ary;
	    }

	    public static String[] split (String input, String splitor) {
	        JMVector ary = splitA(input, splitor);
	        String[] rt = new String[ary.size()];
	        for (int i = 0; i < ary.size(); i++) {
	            rt[i] = (String) ary.get(i);
	        }
	        return rt;
	    }

	    public static String replaceAll (String text, String repl, String with) {
	        if (text == null) {
	            return "";
	        }
	        String rt = "";
	        String[] ary = split(text, repl);
	        for (int i = 0; i < ary.length; i++) {
	            if (i == ary.length - 1) {
	                rt += ary[i];
	            } else {
	                rt += ary[i] + with;
	            }
	        }
	        return rt;
	    }

	    public static String replaceAllIgnoreCase (String text, String repl,
	                                               String with) {

	        String textCopy = text.toLowerCase();
	        String replCopy = repl.toLowerCase();

	        int index = textCopy.indexOf(replCopy);
	        while (index > -1) {
	            String header = text.substring(0, index);
	            String footer = text.substring(index + repl.length());
	            text = header + with + footer;
	            textCopy = text.toLowerCase();
	            index = textCopy.indexOf(replCopy);
	        }
	        return text;
	    }

	    /**
	     * string偱巜掕偝傟偨暥帤楍傪delim偱僩乕僋儞偵暘妱偟丄i偱巜掕偝傟偨僩乕僋儞偺暥帤楍傪曉偡
	     *
	     * @param string丗暘妱尦暥帤楍
	     * @param delim丗嬫愗傝暥帤
	     * @param i丗巜掕埵抲
	     * @return 栠傝抣丗僩乕僋儞暥帤楍
	     */
	    public static String getSplitValue (String string, String delim, int i) {
	        StringTokenizer st = new StringTokenizer(string, delim);
	        JMVector<String> ary = new JMVector<String>();
	        while (st.hasMoreTokens()) {
	            ary.add(st.nextToken());
	        }
	        if (i < 1 || i > ary.size()) {
	            return null;
	        }
	        return (String) ary.get(i - 1);
	    }

	    public static String getYmd (String gengou, String year, String month,
	                                 String day) {
	        return "";
	    }

	    /**
	     * 梄曋斣崋惗惉儊僜僢僪
	     *
	     * @param first丗梄曋斣崋嵟弶偺3寘
	     * @param last丗梄曋斣崋嵟屻偺4寘
	     * @return 栠傝抣丗"999-9999"偺宍幃暥帤楍
	     */

	    public static String getPost (String first, String last) {
	        return first + "-" + last;
	    }

	    /**
	     * 揹榖斣崋惗惉儊僜僢僪
	     *
	     * @param first丗揹榖斣崋偺嵟弶偺5寘
	     * @param center丗揹榖斣崋偺恀傫拞偺5寘
	     * @param last丗揹榖斣崋偺嵟屻偺5寘
	     * @return 栠傝抣丗"99999-99999-99999"偺宍幃偺暥帤楍
	     */
	    public static String getTel (String first, String center, String last) {
	        return first + "-" + center + "-" + last;
	    }

	    /**
	     * 搉偝傟偨暥帤楍傪僠僃僢僋偟丄null 偩偭偨応崌偵偼嬻偺暥帤楍傪曉偡
	     *
	     * @param param丗僠僃僢僋偡傞暥帤楍
	     * @return 栠傝抣丗param偑null偺帪偼挿偝0偺暥帤楍丆偦傟埲奜偼param偺暥帤楍
	     */
	    public static Object defaultString (Object param) {
	        if (param == null) {
	            return "";
	        }
	        return param;
	    }

	    /**
	     * 僥乕僽儖傛傝巜掕偝傟偨僉乕偺暥帤楍昞尰傪庢摼偡傞
	     *
	     * @param hashMap丗専嶕懳徾偺Map僆僽僕僃僋僩
	     * @param key丗専嶕偡傞僉乕
	     * @return 栠傝抣丗僉乕偵懳墳偡傞抣偺暥帤楍丅懳墳偡傞抣偑側偄応崌偼挿偝0偺暥帤楍
	     */
	    public static String getValue (Map hashMap, String key) {
	        return (String) hashMap.get(key);
	    }

	    /**
	     * 懳徾偺暥帤楍撪偺巜掕偝傟偨暥帤楍(repl)傪愭摢偐傜 max 偺夞悢暘丄巜掕偝傟偨暥帤楍(eith)偵曄姺偡傞
	     *
	     * @param text丗擖傟懼偊懳徾偺暥帤楍傪娷傓僥僉僗僩
	     * @param repl丗擖傟懼偊懳徾偲側傞暥帤楍
	     * @param with丗擖傟懼偊傜傟傞暥帤楍
	     * @param max丗擖傟懼偊傪峴偆嵟戝夞悢丅-1
	     *            偺応崌偵偼惂尷側偟
	     * @return 栠傝抣丗暥帤楍偺擖傟懼偊偑峴傢傟偨僥僉僗僩
	     */
	    public static String replace (String text, String repl, String with, int max) {
	        for (int i = 0; i < max; i++) {
	            int index = text.indexOf(repl);
	            if (index > -1) {
	                String header = text.substring(0, index - 1);
	                String footer = text.substring(index + repl.length() - 1);
	                text = header + with + footer;
	            } else {
	                break;
	            }
	        }
	        return text;
	    }

	    /**
	     * 懳徾偺暥帤楍偺抣偺扨埵傪寛掕偡傞
	     *
	     * @param param丗懳徾暥帤楍
	     * @return 栠傝抣丗嬥妟偲扨埵
	     */
	    public static String[] getKingaku (String param) {
	        return null;
	    }

	    /**
	     * 彫悢揰埲壓4寘偵偡傞偨傔偵懌傝側偄暘偩偗0傪晅壛偡傞
	     *
	     * @param param丗敾掕偡傞惓婯壔偝傟偨悢抣
	     * @return 栠傝抣丗彫悢揰埲壓傪4寘偵捈偟偨暥帤楍
	     */
	    public static String formatDecimal (String param) {
	        int index = param.indexOf(".");
	        if (index > -1) {
	            String before = param.substring(0, index);
	            String after = param.substring(index + 1);
	            after = after + "0000";
	            after = after.substring(0, 4);
	            param = before + "." + after;
	        } else {
	            param = param + ".0000";
	        }
	        return param;
	    }

	    /**
	     * 巜掕寘悢傑偱丄侽偱摢傪杽傔傞
	     *
	     * @param resultCode丗懳徾暥帤楍
	     * @param integralSize丗巜掕寘悢
	     * @return 栠傝抣丗曄姺屻暥帤楍
	     */
	    public static String formatZero (String resultCode, int integralSize) {
	        int zerocount = integralSize - resultCode.length();
	        for (int i = 0; i < zerocount; i++) {
	            resultCode = "0" + resultCode;
	        }
	        return resultCode;
	    }

	    /**
	     * 巜掕暥帤楍傪偐傜僇儞儅傪庢傝彍偄偨暥帤楍偲偟偰曉偡
	     *
	     * @param param丗懳徾暥帤楍
	     * @return 栠傝抣丗巜掕暥帤楍偐傜僇儞儅傪庢傝彍偄偨暥帤楍
	     */
	    public static String defaultKingaku (String param) {
	        String rt = "";
	        for (int i = 0; i < param.length(); i++) {
	            String temp = param.substring(i, i + 1);
	            if (temp.equals(",")) {
	            } else {
	                rt = rt + temp;
	            }
	        }
	        return rt;
	    }

	    /**
	     * 巜掕暥帤楍偑null媦傃嬻暥帤偺応崌偼0傪曉偡
	     *
	     * @param param丗懳徾暥帤楍
	     * @return 栠傝抣丗param偑null枖偼挿偝0暥帤楍偺応崌偼"0"丆偦傟埲奜偼param偺暥帤楍
	     */
	    public static String defaultNumber (String param) {
	        if (param == null) {
	            return "0";
	        }
	        if (param.length() == 0) {
	            return "0";
	        }
	        return param;
	    }

	    /**
	     * SystemEncode
	     *
	     * @param str
	     *            String
	     * @return String
	     */
	    public static String SystemEncode (String str) {
	        try {
	            String newStr = "";
	            byte[] bytes = str.getBytes("ISO8859-1");
	            newStr = new String(bytes, "SHIFT_JIS");
	            return newStr;
	        } catch (Exception e) {
	            return str;
	        }
	    }

	    /**
	     * 暥帤楍傪僙僷儗乕僞暥帤偱暘棧偟丄僩乕僋儞暥帤楍傪庢摼偡傞丅<BR>
	     * 僩乕僋儞暥帤楍偵偼僙僷儗乕僞暥帤楍傪娷傔側偄丅
	     *
	     * @return 僩乕僋儞暥帤楍偺攝楍
	     * @param asText
	     *            擖椡暥帤楍
	     * @param acSeparator
	     *            僙僷儗乕僞暥帤楍
	     */
	    public static String[] getTokens (String asText, char acSeparator) {
	        JMVector<String> aTokens = new JMVector<String>();
	        while (asText.length() > 0) {
	            int iPos = asText.indexOf(acSeparator);
	            if (iPos < 0) {
	                aTokens.add(asText);
	                break;
	            }
	            aTokens.add(asText.substring(0, iPos));
	            asText = asText.substring(iPos + 1);
	        }
	        String[] sTokens = (String[]) aTokens.toArray(new String[0]);
	        return sTokens;
	    }

	    /**
	     * 暥帤楍攝楍偺奺暥帤楍傪僙僷儗乕僞暥帤楍傪嫴傫偱侾屄偺暥帤楍偵楢寢偡傞丅
	     *
	     * @param asData
	     *            楢寢偡傞暥帤楍偺攝楍
	     * @param asSeparator
	     *            嬫愗傝暥帤楍
	     * @return 楢寢偟偨暥帤楍
	     */
	    public static String connectWith (String[] asData, String asSeparator) {
	        StringBuffer zBuf = new StringBuffer();
	        for (int i = 0; i < asData.length; i++) {
	            if (i > 0)
	                zBuf.append(asSeparator);
	            zBuf.append(asData[i]);
	        }
	        return zBuf.toString();
	    }

	    public static String setconvIPAddress (String ip) {
	        try {
	            StringBuffer fixlenip = new StringBuffer();
	            StringBuffer zero = new StringBuffer("000");
	            StringTokenizer st = new StringTokenizer(ip, ".");
	            for (int i = 0; st.hasMoreTokens(); ) {
	                zero.delete(0, zero.length());
	                zero.append("000");
	                String dec = st.nextToken();
	                zero.replace(zero.length() - dec.length(), zero.length(), dec);
	                fixlenip.append(zero.toString());
	                fixlenip.append(".");
	                i++;
	            }
	            fixlenip.deleteCharAt(fixlenip.length() - 1);
	            return fixlenip.toString();
	        } catch (Exception ex) {
	            return "000.000.000.000";
	        }
	    }

}

⌨️ 快捷键说明

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