您的位置:首页 > 编程语言 > Java开发

对字符串操作的javabean

2007-04-11 20:30 330 查看
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;

 }

}
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息