设为首页 加入收藏

TOP

用java从字符串中截取指定子串
2014-11-23 20:20:38 】 浏览:9673
Tags:java 字符串 截取 定子

  下面的代码是从最简单的思维去考虑问题的,没有去考虑运行效率问题。测试平台在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.


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇关于jsp页面之间传值的中文乱码总.. 下一篇Java打印EXCEL字符类型设置

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目