下面的代码是从最简单的思维去考虑问题的,没有去考虑运行效率问题。测试平台在mandriva 2009下面。java版本是1.6,因为自己以前较少接触java,所以写一下测试环境。
1.编写代码,将文件名命名为TestGoogle.java.
2.编写代码:
public class TestGoogle
{
public static void main(String args[])
{
String s = new String("http://www.google.cn/search hl=zh-CN&q=siag+office&btnG=Google&meta=&aq=f&oq=");
int n_pos;
n_pos = s.indexOf("&");
String str_temp = new String();
str_temp = s.substring(n_pos+1,s.length());
n_pos = str_temp.indexOf("&");
str_temp = str_temp.substring(0,n_pos);
n_pos = str_temp.indexOf("=");
str_temp = str_temp.substring(n_pos+1,str_temp.length());
System.out.println(str_temp);
}
}
3.编译: javac TestGoogle.java
4.运行: java TestGoogle
5.结果:siag+office.