c=s.charAt(i);
if(c>128||c<0)count++;
count++;
if(count>=limit){
//System.out.println(count);
intx=count%2==0?
++i:
i;
returns.substring(0,x)+"…";
}
}
returns;
}
publicstaticbooleanequal(Strings1,Strings2){
if(s1==null){
returns2==null;
}
returns1.equals(s2);
}
/**
*iso-8859-1转码为GBK
*@paramchangeString
*@throwsUnsupportedEncodingException
*@returnString
*/
publicstaticStringgb2iso(Stringchange)throwsUnsupportedEncodingException{
if(change==null){
change="";
}
try{
//Stringresult=newString(change.getBytes("GBK"),"iso-8859-1");
Stringresult=change;
if(result.length()==change.length()){
returnchange;
}else{
returnresult;
}
}catch(Exceptionex){
return"";
}
}
/**
*补0函数
*@paramiT
*@returnString
*@throwsException
*/
publicstaticStringget00String(intiT){
if(iT>=10){
returnString.valueOf(iT);
}else
return"0"+String.valueOf(iT);
}
/**
*Getbooleanvalueofinputstring
*@paramstrInputString
*@paramdefDefaultvalue
*@returnbooleanvalue
*/
publicstaticBooleangetBoolean(Stringstr,Booleandef){
if(isEmpty(str))returndef;
str=str.toLowerCase();
if(str.equals("true")||str.equals("yes")||str.equals("1"))
returnBoolean.TRUE;
elseif(str.equals("false")||str.equals("no")||str.equals("0"))
returnBoolean.FALSE;
else
returndef;
}
/**
*iftheinputparameterisnotanumberformatstringorisempty,returnthedefaultnumber
*elsereturntheintvalueoftheinputparameter
*@paramnumInputString
*@paramdefDefaultvalue
*@returnParseanintegerfromgivenstring.
*/
publicstaticIntegergetInt(Stringnum,Integerdef){
if(isEmpty(num))
returndef;
Integerret=def;
try{
ret=Integer.valueOf(num);
}catch(NumberFormatExceptionex){
//ignore
}
returnret;
}
/**
*iftheinputparameterisnotanumberformatstringorisempty,returnthedefaultnumber
*elsereturntheLongvalueoftheinputparameter
*@paramnumInputString
*@paramdefDefaultvalue
*@returnParseanlongfromgivenstring.
*/
publicstaticLonggetLong(Stringnum,Longdef){
if(isEmpty(num))
returndef;
Longret=def;
try{
ret=Long.valueOf(num);
}catch(NumberFormatExceptionex){
//ignore
}
returnret;
}
/**
*printstacktraceoftheexcption
*@paramexExceptions
*@returnStacktrace.
*/
publicstaticStringgetStackTrace(Throwableex){
StringWritersw=newStringWriter();
PrintWriterpw=newPrintWriter(sw);
ex.printStackTrace(pw);
returnsw.toString();
}
/**
*把NULL值转化为空("")
*@paramobj传入一个object
*@returnStringstrValue=null,return"";str=str
*/
publicstaticStringgetString(Objectobj){
try{
if(obj==null){
return"";
}
returnobj.toString();
}catch(Exceptionex){
return"";
}
}
/**
*把NULL值转化为空("")
*@paramstrValue
*String传入一个字符串
*@returnStringstrValue=null,return"";str=str
*/
publicstaticStringgetString(StringstrValue){
try{
if(strValue==null){
return"";
}
returnstrValue;
}catch(Exceptionex){
ex.printStackTrace();
return"";
}
}
/**
*iftheinputstringisempty,thenreturnthedefaultstring
*@paramstrInputString
*@paramdefDefaultvalue
*@returnstring
*/
publicstaticStringgetString(Stringstr,Stringdef){
if(isEmpty(str))
returndef;
else
returnstr;
}
/**
*把NULL值转化为空("")
*@paramstrValueString传入一个字符串
*@returnStringstrValue=null,return"0";str=str
*/
publicstaticStringgetStringNum(StringstrValue){
try{
if(strValue==null||strValue.equals("")){
return"0";
}
returnstrValue;
}catch(Exceptionex){
ex.printStackTrace();
return"0";
}
}
/**
*Escapecharacters:
(&/"/>)with&xxxx;
*@paramhtmlInputString
*@returnescapedstring
*/
publicstaticStringhtmlEncode(Stringhtml){
if(StringUtil.isEmpty(html))
return"";
returnhtml.replaceAll("&","&")
.replaceAll("\"",""")
.replaceAll("<","<")
.replaceAll(">",">");
}
publicstaticStringhtmlEncode(Stringhtml,Stringdef){
if(StringUtil.isEmpty(html))
returndef;
else
returnhtmlEncode(html);
}
publicstaticStringhtmlText(Stringstr){
if(StringUtil.isEmpty(str))
return"";
returnstr.replaceAll("&","&")
.replaceAll("\"",""")
.replaceAll("<","<")
.replaceAll(">",">")
.replaceAll("\r\n","
")
.replaceAll("\n","
");
}
publicstaticStringhtmlText(Stringstr,Stringdef){
if(StringUtil.isEmpty(str))
returndef;
else
returnhtmlText(str);
}
/**
*evaluatetheinputstringisnull,ormadeupofspacecharactor
*@paramstrInputString
*@returnifempty,thentrue,elsefalse
*/
publicstaticbooleanisEmpty(Stringstr){
returnstr==null||str.trim().length()==0;
}
publicstaticbooleanisEmpty(Objectobj){
if(obj==null){
returntrue;
}
Stringstr=String.valueOf(obj);
returnstr==null||str.trim().length()==0;
}
/**
*Evaluatethespecificstringisaninteger
*@paramsInputString
*@returnIfinteger,thentrue,elsefalse.
*/
publicstaticbooleanisInteger(Strings){
if(s==null)
returnfalse;
charc;
for(inti=0;ic=s.charAt(i);
if(c<'0'||c>'9')
returnfalse;
}
returntrue;
}
/**
*Alegalnameismadeofalphabet/numeric/'_'andstartswithno-numericcharactor.
*@paramstrInputString
*@returnIflegal,thentrue,else,false.
*/
publicstaticbooleanisLegalName(Stringstr){
if(StringUtil.isEmpty(str))
returnfalse;
for(inti=0;icharc=str.charAt(i);
if(i==0&&c>='0'&&c<='9')returnfalse;
if(!
((c>='a'&&c<='z')||(c>='A'&&c<='Z')||(c>='0'&&c<='9')||c=='_'))
returnfalse;
}
returntrue;
}
/**
*判断字符串是否是纯数字
*
*@paramstr
*@return
*/
publicstaticbooleanisNumric(Stringstr){
if((str==null)||str.equals("")){
returnfalse;
}
booleanflag=true;
Stringmatch="0123456789";
intlen=str.length();
for(inti=0;ichars=str.charAt(i);
if(match.indexOf(s)>=0){
continue;
}else{
flag=false;
break;
}
}
returnflag;
}
/**
*iso-8859-1转码为GBK
*@paramchangeString
*@throwsUnsupportedEncodingException
*@returnString
*/
publicstaticStringiso2gb(Stringchange)throwsUnsupportedEncodingException{
if(change==null){
change="";
}
try{
//Stringresult=newString(change.getBytes("iso-8859-1"),"GBK");
Stringresult=change;
if(result.length()==change.length()){
returnchange;
}else{
returnresult;
}
}catch(Exceptionex){
return"";
}
}
publicstaticStringreplaceIgnoreCase(Stringsrc,Stringpattern,Stringrep){
if(src==null)returnnull;
Patternp=Ppile(pattern,Pattern.CASE_INSENSITIVE);
Matcherm=p.matcher(src);
StringBuffersb=newStringBuffer();
while(m.find()){
m.appendReplacement(sb,rep);
}
m.appendTail(sb);
returnsb.toString();
}
/**
*组合字符串数组为字符串
*@paramsource
*@params
*@return
*/
publicstaticStringjoin(String[]source,Strings){
if(source==null){
return"";
}
StringBuffersb=newStringBuffer();
for(inti=0;isb.append(source[i]);
sb.append(s);
}
if(sb.length()>0){
sb.deleteCharAt(sb.length()-1);
}
returnsb.toString();
}
publicstaticStringjoin(String[]sourc