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.
Wednesday, February 18, 2009
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;
}
* 计算字符串长度,对于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;
}
* 转换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
Java Pattern.quote 使用说明
Java 引用说明:
例子:
Pattern.quote("[test]")
返回 => \Q[test]\E
这样就不需要对正则的特殊字符'['和']'做转义了
\ Nothing,但是引用以下字符
\Q Nothing,但是引用所有字符,直到 \E
\E Nothing,但是结束从 \Q 开始的引用
\Q Nothing,但是引用所有字符,直到 \E
\E Nothing,但是结束从 \Q 开始的引用
例子:
Pattern.quote("[test]")
返回 => \Q[test]\E
这样就不需要对正则的特殊字符'['和']'做转义了
Tuesday, February 03, 2009
urlencode and urldecode in java
import java.net.URLDecoder;
import java.net.URLEncoder;
import junit.framework.TestCase;
public class URLEncodeAndDecode extends TestCase {
public void testUrlEncode() throws Exception {
String str = "中文";
String utf8Code = URLEncoder.encode(str, "UTF-8");
assertEquals("%E4%B8%AD%E6%96%87", utf8Code);
String gbkCode = URLEncoder.encode(str, "GBK");
assertEquals("%D6%D0%CE%C4", gbkCode);
assertEquals("中文", URLDecoder.decode("%E4%B8%AD%E6%96%87", "UTF-8"));
assertEquals("中文", URLDecoder.decode("%D6%D0%CE%C4", "GBK"));
}
}
import java.net.URLEncoder;
import junit.framework.TestCase;
public class URLEncodeAndDecode extends TestCase {
public void testUrlEncode() throws Exception {
String str = "中文";
String utf8Code = URLEncoder.encode(str, "UTF-8");
assertEquals("%E4%B8%AD%E6%96%87", utf8Code);
String gbkCode = URLEncoder.encode(str, "GBK");
assertEquals("%D6%D0%CE%C4", gbkCode);
assertEquals("中文", URLDecoder.decode("%E4%B8%AD%E6%96%87", "UTF-8"));
assertEquals("中文", URLDecoder.decode("%D6%D0%CE%C4", "GBK"));
}
}