Wednesday, February 18, 2009

Remove msn advertises

close msn firstly.
open "C:\WINDOWS\system32\drivers\etc\hosts":
then add below 2 line under 127.0.0.1 localhost:
127.0.0.1 msn.allyes.com

127.0.0.1 rad.msn.com

open msn and try it.

Friday, February 13, 2009

java 计算字符串长度

/**
* 计算字符串长度,对于0-255之间的字符按1计算,大于255的字符按2计算
*
* @param str
* @return
*/
public static int getStringLength(String str) {
int length = 0;
Pattern pattern = Pattern.compile("([^\\x00-\\xff])");
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
length++;
}
return str.length() + length;
}

java unicode字符串转换

/**
* 转换unicode字符串为其对应的实际字符串, UnicodeToString("测试\\u4E2D\\u6587") 输出为: "测试中文"
*
* @param str
* @return
*/
public static String UnicodeToString(String str) {
Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");
Matcher matcher = pattern.matcher(str);
char ch;
while (matcher.find()) {
ch = (char) Integer.parseInt(matcher.group(2), 16);
str = str.replace(matcher.group(1), ch + "");
}
return str;
}

Reference:
http://yuweijun.blogspot.com/2008/06/unicode.html
http://yuweijun.blogspot.com/2008/08/unicode-and-html-entities-in-javascript.html
http://yuweijun.blogspot.com/2008/12/rubyunicodeutf8.html