【www.gdgbn.com--php函数】

jsp教程获取外部连接与替换指定中文函数

截取http://地址
//截取url
pattern pattern = pattern.compile("(http://|https教程://){1}[\w\.\-/:]+");
matcher matcher = pattern.matcher("dsdsdsfdf");
stringbuffer buffer = new stringbuffer();
while(matcher.find()){
buffer.append(matcher.group());
buffer.append("rn");
system.out.println(buffer.tostring());
}

替换指定{}中文字

string str = "java目前的发展史是由{0}年-{1}年";
string[][] object={new string[]{"\{0\}","1995"},new string[]{"\{1\}","2007"}};
system.out.println(replace(str,object));

public static string replace(final string sourcestring,object[] object) {
string temp=sourcestring;
for(int i=0;i string[] result=(string[])object[i];
pattern pattern = pattern.compile(result[0]);
matcher matcher = pattern.matcher(temp);
temp=matcher.replaceall(result[1]);
}
return temp;
}

 

本文来源:http://www.gdgbn.com/jiaocheng/26987/