Blame view

src/com/fh/util/StringUtil.java 1.9 KB
ad5081d3   孙向锦   初始化项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  package com.fh.util;
  /**
   * 字符串相关方法
   *
   */
  public class StringUtil {
  
  	/**
  	 * 将以逗号分隔的字符串转换成字符串数组
  	 * @param valStr
  	 * @return String[]
  	 */
  	public static String[] StrList(String valStr){
  	    int i = 0;
  	    String TempStr = valStr;
  	    String[] returnStr = new String[valStr.length() + 1 - TempStr.replace(",", "").length()];
  	    valStr = valStr + ",";
  	    while (valStr.indexOf(',') > 0)
  	    {
  	        returnStr[i] = valStr.substring(0, valStr.indexOf(','));
  	        valStr = valStr.substring(valStr.indexOf(',')+1 , valStr.length());
  	        
  	        i++;
  	    }
  	    return returnStr;
  	}
  	
  	/**获取字符串编码
  	 * @param str
  	 * @return
  	 */
  	public static String getEncoding(String str) {      
  	       String encode = "GB2312";      
  	      try {      
  	          if (str.equals(new String(str.getBytes(encode), encode))) {      
  	               String s = encode;      
  	              return s;      
  	           }      
  	       } catch (Exception exception) {      
  	       }      
  	       encode = "ISO-8859-1";      
  	      try {      
  	          if (str.equals(new String(str.getBytes(encode), encode))) {      
  	               String s1 = encode;      
  	              return s1;      
  	           }      
  	       } catch (Exception exception1) {      
  	       }      
  	       encode = "UTF-8";      
  	      try {      
  	          if (str.equals(new String(str.getBytes(encode), encode))) {      
  	               String s2 = encode;      
  	              return s2;      
  	           }      
  	       } catch (Exception exception2) {      
  	       }      
  	       encode = "GBK";      
  	      try {      
  	          if (str.equals(new String(str.getBytes(encode), encode))) {      
  	               String s3 = encode;      
  	              return s3;      
  	           }      
  	       } catch (Exception exception3) {      
  	       }      
  	      return "";      
  	   } 
  	
  }