package support;public class URI {
/**
* Return hostname part (without port specification) if the original URI has form [proto]://[hostname][etc].
*
* @return null iff any :// segment is missing
*/
public static String hostname(String uri) {
for (int i=0;i<uri.length();i++) {
if (uri.charAt(i) == ':') {
if (uri.charAt(++i) == '/') {
if (uri.charAt(++i) == '/') {
StringBuilder sb = new StringBuilder(uri.length()-i);
while (++i<uri.length()) {
char c = uri.charAt(i);
if (c==':' || c=='/') break;
sb.append(uri.charAt(i));
}
return sb.toString();
}
}
return null;
}
}
return null;
}
}
/**
* Return hostname part (without port specification) if the original URI has form [proto]://[hostname][etc].
*
* @return null iff any :// segment is missing
*/
public static String hostname(String uri) {
for (int i=0;i<uri.length();i++) {
if (uri.charAt(i) == ':') {
if (uri.charAt(++i) == '/') {
if (uri.charAt(++i) == '/') {
StringBuilder sb = new StringBuilder(uri.length()-i);
while (++i<uri.length()) {
char c = uri.charAt(i);
if (c==':' || c=='/') break;
sb.append(uri.charAt(i));
}
return sb.toString();
}
}
return null;
}
}
return null;
}
}
楼主【miaoqiang2040】截止到2008-06-27 10:45:14的历史汇总数据(不包括此帖):
发帖数:33 发帖分:420
结贴数:21 结贴分:340
未结数:12 未结分:80
结贴率:63.64 % 结分率:80.95 %
楼主加油