`
utt62utt
  • 浏览: 14883 次
最近访客 更多访客>>
社区版块
存档分类
最新评论

自己做的一组字符串操作方法,可能会用上。-azure2a-iteye技术网站

 
阅读更多

自己做的一组字符串操作方法,可能会用上。-azure2a-iteye技术网站
2011年07月01日
   不过都是用的String效率可能不太高。 
  package util; 
  import java.io.UnsupportedEncodingException; 
  import java.security.MessageDigest; 
  import java.util.Date; 
  import java.util.Map; 
  /** 
  * Title:  
  * Description:  
  * Copyright: Copyright (c) 2003 
  * Company:  
  * @author unascribed 
  * @version 1.0 
  */ 
  public class StringUtil { 
  private final static String[] hexDigits = { 
  "0", "1", "2", "3", "4", "5", "6", "7", 
  "8", "9", "a", "b", "c", "d", "e", "f"}; 
  /** 
  * 转换字节数组为16进制字串 
  * @param b 字节数组 
  * @return 16进制字串 
  */ 
  public static String byteArrayToHexString(byte[] b) { 
  StringBuffer resultSb = new StringBuffer(); 
  for (int i = 0; i -1); 
  return result; 
  } 
  /** 
  * 
  * @param file 
  * @param split 
  * @return 按照split分隔符取得文件的类型 
  */ 
  public static String getFileType(String file,String split){ 
  String in=file.trim(); 
  String type=in.substring(in.lastIndexOf(split)+1,in.lengt h()); 
  return type; 
  } 
  /** 
  * 
  * @param file 
  * @param split 
  * @return按照split分隔符取得文件的名字 
  */ 
  public static String getFileName(String file,String split){ 
  String in=file.trim(); 
  String type=in.substring(0,in.lastIndexOf(split)); 
  return type; 
  } 
  /** 
  * 
  * @param s 
  * @param strcheck 
  * @return 检测s是否为待检验的类型 
  */ 
  public static boolean fileTypeChecker(String s,String strcheck){ 
  boolean result=false;     
  String type=getFileType(s,"."); 
  String[] strCheck=splitStr(strcheck,","); 
  for(String check:strCheck)result=result||type.equals(check.tr im()); 
  return result; 
  } 
  /** 
  * 
  * @param strInput 
  * @param strCheck 
  * @return 检验strInput串中是否含有strCheck中的串 
  */ 
  public static boolean checkStr(String[] strInput,String[] strCheck){ 
  boolean result=false; 
  for(String input:strInput)result=result||inStr(input,strCheck ); 
  return result; 
  } 
  /** 
  * 
  * @param str 
  * @param length 
  * @param insertStr 
  * @return 按照长度在某一段字符串中插入另一段字符 
  */ 
  public static String insertStr(String str,int length,String insertStr){ 
  String result=""; 
  int total=str.length(); 
  int i=0; 
  while(true){ 
  if((i+length) strMap){ 
  for(Map.Entry entry:strMap.entrySet()){ 
  s=s.replaceAll(entry.getKey(),entry.getValue()); 
  } 
  return s; 
  } 
  /** 
  * 
  * @param str 
  * @param length 
  * @param r 
  * @return 切断字符串 
  */ 
  public static String getStrByLength(String str,int length,String r){ 
  if(str.length() strMap=new HashMap(); 
  //strMap.put("fuck", "[-bi-]"); 
  //strMap.put("逼", "[-呵呵-]"); 
  //System.out.println(replaceStr("fuck you 逼!!",strMap)); 
  //for(int i:splitStr("1,232,2312,231,312",",",1))System.out. println(i); 
  System.out.println(getFileName("ab.txt","."));   
  System.out.println(MD5Encode(new Date().toString()));    
  } 
  } 
  
  
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics