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

📄 strutil.java

📁 cwbbs 云网论坛源码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package cn.js.fan.util;import java.io.UnsupportedEncodingException;import java.util.regex.Pattern;import java.util.regex.Matcher;import java.util.*;import java.text.*;import javax.servlet.http.*;import java.net.URLEncoder;import cn.js.fan.web.Global;import cn.js.fan.web.SkinUtil;import java.io.StringWriter;import java.io.PrintWriter;import com.cloudwebsoft.framework.util.LogUtil;public class StrUtil {    public static int INT_HELPER = 0;    public StrUtil() {    }        public static String UrlEncode(String str, String charset) {        if (str == null)            return "";        String s = str;        try {            s = URLEncoder.encode(str, charset);        } catch (Exception e) {        }        return s;    }        public static String UrlEncode(String str) {        return UrlEncode(str, "utf-8");    }        public static String[] split(String str, String token) {        str = StrUtil.getNullStr(str).trim();        if (str.equals(""))            return null;        return str.split(token);    }        public static String getURL(HttpServletRequest request) {        return request.getRequestURL() + "?" + request.getQueryString();            }        public static String getUrl(HttpServletRequest request) {        String str = "";        str = request.getRequestURL() + "?" +              UrlEncode(request.getQueryString(), "utf-8");        return str;    }        public static String getIp(HttpServletRequest request) {        String ip = request.getHeader("HTTP_X_FORWARDED_FOR");         if (ip == null) {            ip = StrUtil.getNullStr(request.getRemoteAddr());        }        return getNullString(ip);    }        public static String getNullString(String str) {        return (str == null) ? "" : str;    }        public static String getNullStr(String str) {        return (str == null) ? "" : str;    }        public static String replace(String strSource, String strFrom, String strTo) {        if (strSource.equals("") || strSource == null)            return strSource;        String strDest = "";        int intFromLen = strFrom.length();        int intPos;        if (strSource == null || (strSource.trim()).equals(""))            return strSource;        while ((intPos = strSource.indexOf(strFrom)) != -1) {            strDest = strDest + strSource.substring(0, intPos);            strDest = strDest + strTo;            strSource = strSource.substring(intPos + intFromLen);        }        strDest = strDest + strSource;        return strDest;    }        public static String sqlstr(String str) {        if (str == null || (str.trim()).equals("")) {            str = "\'\'";            return str;        }        str = "\'" + replace(str, "\'", "\'\'") + "\'";        return str;    }        public static String UnicodeToGB(String strIn) {        return UnicodeToUTF8(strIn);    }        public static int UTF8Len(String str) {        int k = 0;        for (int i = 0; i < str.length(); i++) {            if (str.charAt(i) > 255)                k += 2;            else                k += 1;        }        return k;    }        public static String Unicode2GB(String strIn) {        String strOut = null;        if (strIn == null || (strIn.trim()).equals(""))            return strIn;        try {            byte[] b = strIn.getBytes("ISO8859_1");            strOut = new String(b, "GB2312");         } catch (Exception e) {}        return strOut;    }        public static String UnicodeToUTF8(String strIn) {        String strOut = null;        if (strIn == null || (strIn.trim()).equals(""))            return strIn;        try {            byte[] b = strIn.getBytes("ISO8859_1");                        strOut = new String(b, "utf-8");         } catch (Exception e) {}        return strOut;    }        public static String GBToUnicode(String strIn) {        byte[] b;        String strOut = null;        if (strIn == null || (strIn.trim()).equals(""))            return strIn;        try {            b = strIn.getBytes("GB2312");            strOut = new String(b, "ISO8859_1");        } catch (UnsupportedEncodingException e) {}        return strOut;    }        public static String UTF8ToUnicode(String strIn) {        byte[] b;        String strOut = null;        if (strIn == null || (strIn.trim()).equals(""))            return strIn;        try {            b = strIn.getBytes("utf-8");            strOut = new String(b, "ISO8859_1");        } catch (UnsupportedEncodingException e) {}        return strOut;    }        public static String p_center(String str) {        return "<p align=center>" + str + "</p>";    }        public static String p_center(String str, String color) {        return "<p align=center><font color='" + color + "'>" + str +                "</font></p>";    }        public static String makeErrMsg(String msg) {        String str = "<BR><BR><BR>";        str += "<table width='70%' height='50' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='blue'>";        str += "<tr>";        str += "<td bgcolor='#FFFFFF' align='center'><b><font color=red>" + msg +                "</font></b></td>";        str += "</tr>";        str += "</table>";        return str;    }        public static String makeErrMsg(String msg, String textclr, String bgclr) {        String str = "<BR><BR><BR>";        str += "<table width='70%' height='50' border='0' align='center' cellpadding='0' cellspacing='1' bgcolor='" +                bgclr + "'>";        str += "<tr>";        str += "<td bgcolor='#FFFFFF' align='center'><font color='" + textclr +                "'><b>" + msg + "</b></font></td>";        str += "</tr>";        str += "</table>";        return str;    }        public static String waitJump(String msg, int t, String url) {        String str = "";        String spanid = "id" + System.currentTimeMillis();        str = "\n<ol><b><span id=" + spanid + "> 3 </span>";        str += "秒钟后系统将自动返回... </b></ol>";        str += "<ol>" + msg + "</ol>";        str += "<script language=javascript>\n";        str += "<!--\n";        str += "function tickout(secs) {\n";        str += spanid + ".innerText = secs;\n";        str += "if (--secs > 0) {\n";        str += "  setTimeout('tickout(' +secs + ')', 1000);\n";        str += "}\n";        str += "}\n";        str += "tickout(" + t + ");\n";        str += "-->\n";        str += "</script>\n";        str += "<meta http-equiv=refresh content=" + t + ";url=" + url + ">\n";        return str;    }        public static String Alert_Redirect(String msg, String toUrl) {        String str = "";        str = "<script language=javascript>\n";        str += "<!--\n";        str += "alert(\"" + msg + "\")\n";        if (!toUrl.equals(""))            str += "location.href=\"" + toUrl + "\"\n";        str += "-->\n";        str += "</script>\n";        return str;    }        public static String Alert_Back(String msg) {        String str = "";        str = "<script language=javascript>\n";        str += "<!--\n";        str += "alert(\"" + msg + "\")\n";        str += "history.back()\n";        str += "-->\n";        str += "</script>\n";        return str;    }        public static String Alert(String msg) {        String str = "";        str = "<script language=javascript>\n";        str += "<!--\n";        str += "alert(\"" + msg + "\")\n";        str += "-->\n";        str += "</script>\n";        return str;    }        public static float toFloat(String str, float defaultValue) {        float d = defaultValue;        try {            d = Float.parseFloat(str);        } catch (Exception e) {            LogUtil.getLog(StrUtil.class).error("toFloat" + e.getMessage());        }        return d;    }        public static float toFloat(String str) {        return toFloat(str, 0.0f);    }        public static double toDouble(String str, double defaultValue) {        double d = defaultValue;        try {            d = Double.parseDouble(str);        } catch (Exception e) {            LogUtil.getLog(StrUtil.class).error("toDouble" + e.getMessage());        }        return d;    }        public static double toDouble(String str) {        return toDouble(str, 0.0);    }        public static int toInt(String str, int defaultValue) {        int d = defaultValue;        try {            d = Integer.parseInt(str);        } catch (Exception e) {                    }        return d;    }        public static int toInt(String str) {        return toInt(str, -1);    }        public static long toLong(String str, long defaultValue) {        long d = defaultValue;        try {            d = Long.parseLong(str);        } catch (Exception e) {                    }        return d;    }        public static long toLong(String str) {        return toLong(str, -1);    }        public static boolean isNumeric(String s) {        if (s == null)            return false;        boolean flag = true;        char[] numbers = s.toCharArray();        if (numbers.length == 0)            return false;         for (int i = 0; i < numbers.length; i++) {            if (!Character.isDigit(numbers[i])) {                flag = false;                break;            }        }        return flag;    }    public static boolean isDouble(String str) {

⌨️ 快捷键说明

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