📄 stringutil.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: StringUtil.java
package com.cwc.util;
import java.io.*;
import java.net.*;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Enumeration;
import javax.servlet.http.*;
// Referenced classes of package com.cwc.util:
// Handler, Md5
public class StringUtil
implements Handler
{
public StringUtil()
{
}
public static final String replaceString(String s, String strb, String strh)
{
if(s == null || s.length() == 0)
return s;
StringBuffer tmp = new StringBuffer();
int k;
while((k = s.indexOf(strb)) >= 0)
{
tmp.append(s.substring(0, k));
tmp.append(strh);
s = s.substring(k + strb.length());
}
if(s.length() > 0)
tmp.append(s);
return tmp.toString();
}
public static final String replaceEnter(String s)
{
if(s == null || s.length() == 0)
{
return s;
} else
{
s = replaceString(s, "\r\n", "<br>");
s = replaceString(s, "\n", "<br>");
return s;
}
}
public static final String ascii2Html(String s)
{
if(s == null || s.length() == 0)
{
return s;
} else
{
s = replaceString(s, "&", "&");
s = replaceString(s, "\"", """);
s = replaceString(s, "<", "<");
s = replaceString(s, ">", ">");
s = replaceString(s, " ", " ");
s = replaceString(s, "'", "'");
s = replaceString(s, "\n", "<br>");
return s;
}
}
public static final String html2Ascii(String s)
{
if(s == null || s.length() == 0)
{
return s;
} else
{
s = replaceString(s, "&", "&");
s = replaceString(s, """, "\"");
s = replaceString(s, "<", "<");
s = replaceString(s, ">", ">");
s = replaceString(s, " ", " ");
s = replaceString(s, "'", "'");
s = replaceString(s, "<br>", "\r\n");
return s;
}
}
public static final String GBK2ISO(String InputStr)
{
try
{
return new String(InputStr.getBytes("GBK"), "ISO8859_1");
}
catch(Exception e)
{
System.err.println("GBK2ISO??????????!");
}
return null;
}
public static final String GB23122UTF8(String InputStr)
{
try
{
return new String(InputStr.getBytes("GB2312"), "UTF-8");
}
catch(Exception e)
{
System.err.println("GBK2ISO??????????!");
}
return null;
}
public static final String ISO2UTF8(String InputStr)
{
try
{
return new String(InputStr.getBytes("ISO8859-1"), "UTF-8");
}
catch(Exception e)
{
System.out.println("ISO2UTF8");
}
return null;
}
public static final String Windows1252UTF8(String InputStr)
{
try
{
return new String(InputStr.getBytes("Windows-1252"), "UTF-8");
}
catch(Exception e)
{
System.out.println("Windows1252UTF8");
}
return null;
}
public static final String UTF82ISO(String InputStr)
{
try
{
return new String(InputStr.getBytes("UTF-8"), "ISO8859-1");
}
catch(Exception e)
{
System.err.println("GBK2ISO??????????!");
}
return null;
}
public static final String UTF82GBK(String InputStr)
{
try
{
return new String(InputStr.getBytes("UTF-8"), "GBK");
}
catch(Exception e)
{
return null;
}
}
public static final String UTF82GB2312(String InputStr)
{
try
{
return new String(InputStr.getBytes("UTF-8"), "gb2312");
}
catch(Exception e)
{
return null;
}
}
public static String ISO2GBK(String InputStr)
{
try
{
return new String(InputStr.getBytes("ISO8859_1"), "GBK");
}
catch(Exception e)
{
System.err.println("ISO2GBK??????????!");
}
return null;
}
public static final String dealNull(String str)
{
if(str == null)
return "";
else
return str;
}
public static final String dealSql(String sql)
{
if(sql == null || sql.trim().length() == 0)
return sql;
String s = replaceString(sql.trim().replaceAll("\r", ""), "'", "''");
s = replaceString(s, "\\", "\\\\");
if(s.charAt(0) != '\'')
s = "'" + s;
if(!s.endsWith("'"))
s = s + "'";
return s;
}
public static final String getMultiString(String paraName[])
{
return getMultiString(paraName, ",");
}
public static final String getMultiString(String paraName[], String spChar)
{
if(paraName == null || paraName.length == 0)
return "";
StringBuffer valuesTemp = new StringBuffer();
String specialChar = spChar;
String values[] = paraName;
int i = 0;
for(i = 0; i < values.length - 1; i++)
valuesTemp.append(values[i] + specialChar);
valuesTemp.append(values[i]);
return valuesTemp.toString();
}
public static final boolean isBlank(String str)
{
return str == null || str.trim().length() == 0;
}
public static final String getString(String strName)
{
return getString(strName, ((String) (null)));
}
public static final String getString(String strName, String def)
{
if(strName == null)
return def;
else
return strName;
}
public static final int getInt(String strName)
{
return getInt(strName, 0);
}
public static final int getInt(String strName, int defaultvalue)
{
if(strName == null)
return defaultvalue;
try
{
return Integer.parseInt(strName.trim());
}
catch(Exception e)
{
return defaultvalue;
}
}
public static final long getLong(String strName)
throws Exception, NumberFormatException
{
if(strName == null)
throw new Exception("getLong(String strName):Input value is NULL!");
try
{
return Long.parseLong(strName.trim());
}
catch(NumberFormatException e)
{
throw new NumberFormatException("getLong NumberFormatException for input string:" + strName);
}
}
public static final float getFloat(String strName)
throws Exception, NumberFormatException
{
if(strName == null)
throw new Exception("Input value is NULL!");
try
{
return Float.parseFloat(strName.trim());
}
catch(NumberFormatException e)
{
throw new NumberFormatException("getFloat(String) NumberFormatException for input string:" + strName);
}
}
public static final float getFloat(HttpServletRequest request, String strName)
throws Exception, NumberFormatException
{
String val = request.getParameter(strName);
if(val == null)
return 0.0F;
try
{
return Float.parseFloat(val.trim());
}
catch(NumberFormatException e)
{
throw new NumberFormatException("getFloat(request) NumberFormatException for input string:" + val);
}
}
public static final float getFloat(HttpServletRequest request, String strName, float def)
throws Exception, NumberFormatException
{
String val = request.getParameter(strName);
if(val == null)
{
System.out.println("val is null,so return default!");
return def;
}
try
{
return Float.parseFloat(val.trim());
}
catch(NumberFormatException e)
{
System.out.println("getFloat(HttpServletRequest request,String strName,float def) NumberFormatException for input string:" + val + ",so return default!");
}
return def;
}
public static final long getLong(String strName, long defaultvalue)
{
if(strName == null)
return defaultvalue;
try
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -