package computer;
import java.util.regex.Matcher;
import java.io.*;
import java.util.regex.Pattern ;
public class Str {
public String toChinese(String str){
if(str==null||str.length()<1){
str="";
}else{
try{
str=(new String(str.getBytes("iso-8859-1"),"GB2312"));
}catch(UnsupportedEncodingException e){
System.err.print(e.getMessage());
e.printStackTrace();
return str;
}
}
return str;
}
public String dbEnconde(String str){
if(str==null){
str="";
}else{
try{
str=str.trim();
}catch(Exception e){
System.err.print(e.getMessage());
e.printStackTrace();
return str;
}
}
return str;
}
public int toInt(String str){
int b=0;
try{
b=Integer.parseInt(str);
}catch(NumberFormatException e){
System.out.println("用户名不允许特殊字符");
}
return b;
}
public boolean isNumeric(String str)
{
Pattern pattern = Pattern.compile("[0-9]*");
Matcher isNum = pattern.matcher(str);
if( !isNum.matches() )
{
return false;
}
return true;
}
}