// FrontEnd Plus GUI for JAD
// DeCompiled : StringTool.class
package com.util;
import java.io.PrintStream;
import java.util.GregorianCalendar;
import java.util.Vector;
// Referenced classes of package com.converse.util:
// TException
public class StringTool
{
public StringTool()
{
}
public static String getSubString(String strSource, String strStart, String strEnd)
{
if(strSource == null || strStart == null || strEnd == null)
return null;
int nTmp1 = strSource.indexOf(strStart);
if(nTmp1 < 0)
return null;
String strTmp = strSource.substring(nTmp1);
int nTmp2 = strTmp.indexOf(strEnd);
if(nTmp2 < 0)
return null;
else
return strTmp.substring(strStart.length(), nTmp2);
}
public static boolean isDouble(String str)
{
try
{
toDouble(str);
return true;
}
catch(Exception e)
{
return false;
}
}
public static boolean isFloat(String str)
{
try
{
toFloat(str);
return true;
}
catch(Exception e)
{
return false;
}
}
public boolean isInt(String str)
{
try
{
toInt(str);
return true;
}
catch(Exception e)
{
return false;
}
}
public String replace(String strSrc, String strOld, String strNew)
{
if(strSrc == null)
return "";
StringBuffer sb = new StringBuffer();
int oldlen = strOld.length();
int pos = 0;
int lastpos;
for(lastpos = 0; lastpos < strSrc.length() && (pos = strSrc.indexOf(strOld, lastpos)) > -1; lastpos = pos + oldlen)
{
sb.append(strSrc.substring(lastpos, pos));
sb.append(strNew);
}
if(lastpos < strSrc.length())
sb.append(strSrc.substring(lastpos));
return new String(sb);
}
public String replaceReturn(String src, String returnsymbol, String pLang)
{
int i = 0;
String des = "";
boolean tableflag = false;
boolean multilingualflag = false;
if(src == null)
return "";
if(!pLang.equals("CHN") && !pLang.equals("BIG5"))
multilingualflag = true;
while((i = src.indexOf(returnsymbol)) != -1)
{
des = des + src.substring(0, i);
src = src.substring(i + returnsymbol.length());
if(multilingualflag)
des = des + "<br>";
else
if(tableflag)
des = des + "<br>";
else
if(src.indexOf(returnsymbol) == 0)
{
des = des + "<br><br>";
src = src.substring(returnsymbol.length());
} else
if(src.indexOf("\u2500") == 0 || src.indexOf("\u2501") == 0 || src.indexOf("\u2504") == 0 || src.indexOf("\u2505") == 0 || src.indexOf("\u2508") == 0 || src.indexOf("\u2509") == 0 || src.indexOf("-") == 0 || src.indexOf("\u250C") == 0 || src.indexOf("\uFF0D") == 0)
{
des = des + "<br>";
tableflag = true;
} else
if(src.indexOf("\u3000") == 0 || src.indexOf(" ") == 0 || src.indexOf("\uE814") == 0)
{
des = des + "<br> ";
src = src.substring(1);
} else
if(src.length() > 0 && src.charAt(0) <= '\177')
des = des + "<br>";
}
if(src != null)
return des + src;
else
return des;
}
public static Vector split(String str, String strSeparator)
{
Vector vReturn = new Vector();
if(str == null)
return null;
if(strSeparator == null || strSeparator.equalsIgnoreCase("") || str.indexOf(strSeparator) < 0)
{
vReturn.add(0, str);
return vReturn;
}
int nTmp = strSeparator.length();
int nTmp2;
for(; str.indexOf(strSeparator) >= 0; str = str.substring(nTmp2 + nTmp))
{
nTmp2 = str.indexOf(strSeparator);
vReturn.add(str.substring(0, nTmp2));
}
vReturn.add(str);
return vReturn;
}
public static double toDouble(String str)
throws TException
{
try
{
return Double.parseDouble(str);
}
catch(Exception e)
{
throw new TException("\u9519\u8BEF\u7684\u6570\u5B57\u683C\u5F0F\uFF01", "StringTool.toDouble()", e);
}
}
public static float toFloat(String str)
throws TException
{
try
{
return Float.parseFloat(str);
}
catch(Exception e)
{
throw new TException("\u9519\u8BEF\u7684\u6570\u5B57\u683C\u5F0F\uFF01", "StringTool.toFloat()", e);
}
}
public static String toGBK(String str)
throws TException
{
if(str == null)
return null;
try
{
return new String(str.getBytes("iso-8859-1"), "GBK");
}
catch(Exception e)
{
throw new TException("\u8F6C\u6362\u4E3AGBK\u65F6\u9519\u8BEF", "StringTool.toGBK()", e);
}
}
public static String toCharset(String str, String sCharset)
throws TException
{
if(str == null)
return null;
try
{
return new String(str.getBytes(), sCharset);
}
catch(Exception e)
{
throw new TException("\u8F6C\u6362\u4E3A" + sCharset + "\u65F6\u9519\u8BEF", "StringTool.toCharset()", e);
}
}
public static int toInt(String str)
throws TException
{
try
{
return Integer.parseInt(str);
}
catch(Exception e)
{
throw new TException("\u9519\u8BEF\u7684\u6570\u5B57\u683C\u5F0F\uFF01", "StringTool.toInt(str)", e);
}
}
public static int toInt(String str, int nMinLength, int nMaxLength)
throws TException
{
if(str.length() < nMinLength)
throw new TException("\u6570\u5B57\u5C0F\u4E8E\u6307\u5B9A\u7684\u957F\u5EA6" + nMinLength, "StringTool.toInt(str,nMaxLength)");
if(str.length() > nMaxLength)
throw new TException("\u6570\u5B57\u5927\u4E8E\u6307\u5B9A\u7684\u957F\u5EA6" + nMaxLength, "StringTool.toInt(str,nMaxLength)");
else
return toInt(str);
}
public static String encrypt(String strIn, int nMode)
throws TException
{
if(strIn == null)
throw new TException("\u76EE\u6807\u5B57\u7B26\u4E32\u4E0D\u80FD\u4E3Anull", "StringTool.encrypt()");
if(nMode != 1 && nMode != 2)
throw new TException("\u7F16\u7801\u6A21\u5F0F\u53C2\u6570\u65E0\u6548,\u6709\u6548\u503C\u4E3A1\u62162", "StringTool.encrypt()");
String strReturn = null;
boolean flag = false;
if(nMode == 1)
flag = true;
if(strIn.equals(""))
return "";
String outString;
if(flag)
{
char encryptString[] = encryptCore(flag, strIn);
String item = new String();
outString = new String();
for(int i = 0; i < encryptString.length; i++)
{
int nItem = encryptString[i];
item = String.valueOf(nItem);
if(i == 0)
outString = item;
else
outString = outString + "^" + item;
}
}
评论0