自己做的一组字符串操作方法,可能会用上。-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()));
  }
  }
  
  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值