今天工作还蛮顺利的,应该都搞定了,只是集群貌似任务过多跑不起来,明天早点来运行吧。
总结一下,转码方法。。
GB2312
public static String gb2312ToWord(String str) throws Exception { String result = ""; byte[] bytes = new byte[str.length() / 2]; for (int i = 0; i < bytes.length; i++) { byte high = Byte.parseByte(str.substring(i*2, i*2+1), 16); byte low = Byte.parseByte(str.substring(i*2+1, i*2+2), 16); bytes[i] = (byte) (high << 4 | low); } if (bytes.length > 0) { result = new String(bytes, "gbk"); } return result; }
UTF-8
public static void main(String[] args) throws Exception { String str = "%25E5%25B0%258F%25E8%2599%25BE%25E6%259D;"; //String str = "山东临沂一" //分割时用"&#",向整数转换时用Integer.parseInt(xx,10); String[] strs = str.split("%"); StringBuilder sb = new StringBuilder(); int temp; for(int i=1; i<strs.length; i++) { temp = Integer.parseInt(strs[i].substring(0,strs[i].length()-1),16); sb.append((char)temp); } System.out.println(sb.toString()); }
把这些弄出来后开会时前辈告我java函数
String kw="%E9%87%8D%E7%94%9F%E4%B9%8B%E5%9C%B0%E4%BA%A7%E5%A4%A7%E4%BA%A8%20%E5%85%AB%E7%88%AA%E7%AB%A0%E9%B1%BC%20%E5%B0%8F%E8%AF%B4"; String a =URLDecoder.decode(kw,"UTF-8"); System.out.println(a);
不早说。。5555~~~
还有一点需要留意的!!!
str.contains("abc");
这个方法匹配出的"abc",必须是连续的“addbc”这不能算包括!!
于是瓦就用了matches("[0-9]*")
附:
java中判断字符串是否为数字的方法的几种方法
ava中判断字符串是否为数字的方法: 1.用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = 0; i < str.length(); i++){ System.out.println(str.charAt(i)); if (!Character.isDigit(str.charAt(i))){ return false; } } return true; } 2.用正则表达式 首先要import java.util.regex.Pattern 和 java.util.regex.Matcher public boolean isNumeric(String str){ Pattern pattern = Pattern.compile("[0-9]*"); Matcher isNum = pattern.matcher(str); if( !isNum.matches() ){ return false; } return true; } 3.使用org.apache.commons.lang org.apache.commons.lang.StringUtils; boolean isNunicodeDigits=StringUtils.isNumeric("aaa123456789"); http://jakarta.apache.org/commons/lang/api-release/index.html下面的解释: isNumeric public static boolean isNumeric(String str)Checks if the String contains only unicode digits. A decimal point is not a unicode digit and returns false. null will return false. An empty String ("") will return true. StringUtils.isNumeric(null) = false StringUtils.isNumeric("") = true StringUtils.isNumeric(" ") = false StringUtils.isNumeric("123") = true StringUtils.isNumeric("12 3") = false StringUtils.isNumeric("ab2c") = false StringUtils.isNumeric("12-3") = false StringUtils.isNumeric("12.3") = false Parameters: str - the String to check, may be null Returns: true if only contains digits, and is non-null 上面三种方式中,第二种方式比较灵活。 第一、三种方式只能校验不含负号“-”的数字,即输入一个负数-199,输出结果将是false; 而第二方式则可以通过修改正则表达式实现校验负数,将正则表达式修改为“^-?[0-9]+”即可,修改为“-?[0-9]+.?[0-9]+”即可匹配所有数字。原文链接: http://www.cnblogs.com/astroboyx/archive/2009/04/18/2739885.html
终于有按时下班的时候啦啦啦~~~