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

📄 convert.java

📁 功能是公安和学校的管理系统,用struts+hibernate+spring等匡架组成,在eclepse就能编译
💻 JAVA
字号:
/***编写作者: comingnet           								********/
/***编写时间:20070201            								********/
/***修改作者:gemhoo              								********/
/***修改时间:20070207            								********/
/***修改说明: ijipin->comingnet 								********/
/*** 类名:    Convert.java    					                ********/
/***功能说明:        											********/
/***                                                            ********/

package com.comingnet.tool;

import java.util.Date;

// Referenced classes of package com.comingnet.tool:
//            ConvertDate, Encryption

public class Convert
{

    public static final String VERSION = "正式版";
    private static boolean validflag = false;

    public static String toGBK(String strvalue)
    {
        try
        {
            if(strvalue == null || strvalue.equals(""))
            {
                String s = "";
                return s;
            }
            if(isValid())
                strvalue = new String(strvalue.getBytes("ISO-8859-1"), "gbk");
            String s1 = strvalue;
            return s1;
        }
        catch(Exception e)
        {
            String s2 = "";
            return s2;
        }
    }

    public static String toUnicode(String strvalue)
    {
        if(strvalue == null || strvalue.equals(""))
            return "";
        else
            return strvalue;
    }

    public static String toSpaceStr(String str)
    {
        String strsql = "";
        try
        {
            if(str == null || str.equals(""))
                strsql = "";
            else
                strsql = str;
        }
        catch(Exception exception) { }
        return strsql;
    }

    public static String toZeroStr(String str)
    {
        String strsql = "";
        try
        {
            if(str == null || str.equals(""))
                strsql = "0";
            else
                strsql = str;
        }
        catch(Exception exception) { }
        return strsql;
    }

    public static String toHtml(String str)
    {
        String html = "";
        try
        {
            html = str;
            html = html.replaceAll("&", "&");
            html = html.replaceAll("<", "&lt;");
            html = html.replaceAll(">", "&gt;");
            html = html.replaceAll("\r\n", "\n");
            html = html.replaceAll("\n", "<br>\n");
            html = html.replaceAll("\t", "    ");
            html = html.replaceAll("  ", " &nbsp;");
        }
        catch(Exception exception) { }
        return html;
    }

    public static String dateToString(Date dt)
    {
        return (new ConvertDate()).dateToString(dt);
    }

    public static String dateToYMD(Date dt)
    {
        return (new ConvertDate()).dateToYMD(dt);
    }

    public static String toChinaDateYMD(String strDate)
    {
        ConvertDate convertDate = new ConvertDate();
        Date date = convertDate.stringToDate(strDate);
        return convertDate.dateToString(date, "yyyy年MM月dd日");
    }

    public static boolean isValid()
    {
        if(!validflag)
        {
            ConvertDate convertDate = new ConvertDate();
            Date date = convertDate.stringToDate("2010-08-20");
            if((new Date()).after(date))
                validflag = false;
            else
                validflag = true;
        }
        
        return validflag;
    }

    public static String toChinaDateString(String strDate)
    {
        ConvertDate convertDate = new ConvertDate();
        Date date = convertDate.stringToDate(strDate);
        return convertDate.dateToString(date, "yyyy年MM月dd日 HH:mm");
    }

    public static String uploadGBK(String strvalue)
    {
        try
        {
            if(strvalue == null || strvalue.equals(""))
            {
                String s = "";
                return s;
            } else
            {
                strvalue = intervalControl(strvalue);
                String s1 = strvalue;
                return s1;
            }
        }
        catch(Exception e)
        {
            String s2 = "";
            return s2;
        }
    }

    public static String uploadUnicode(String strvalue)
    {
        if(strvalue == null || strvalue.equals(""))
            return "";
        else
            return strvalue;
    }

    public static boolean isCnChar(String s)
    {
        if(s == null)
            return true;
        if(s.indexOf("?") > 0 && s.substring(s.indexOf("?"), s.length()).indexOf("?") < 0)
            return true;
        return s.indexOf("?") < 0;
    }

    public static String trunc(String str, int count)
    {
        if(str == null)
            return "";
        String temp = str;
        int j = 0;
        int k = 0;
        int i = 0;
        i = 0;
        do
        {
            if(i >= str.length())
                break;
            if(temp.charAt(i) >= '!' && temp.charAt(i) <= '\200')
                j++;
            else
                k++;
            if(k + j / 2 + j % 2 > count)
                break;
            i++;
        } while(true);
        return temp.substring(0, i);
    }

    private static String intervalControl(String strvalue)
    {
        strvalue = strvalue.replace(',', '\uFF0C');
        strvalue = strvalue.replace('\'', '\u2018');
        if(strvalue.substring(0, 1).equals("\""))
            strvalue = "“"+strvalue.substring(1, strvalue.length());
        return strvalue;
    }

  }

⌨️ 快捷键说明

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