zoukankan      html  css  js  c++  java
  • 使用java中的String类操作复杂的字符串

    今天自己出了一道题差点把自己难住……
    题目是这样的:
    已知有三条查询的sql语句,小明不小心写一块了,你帮他拆分开。sql语句为:"select * from books where bid = 1 select * from cate where name = ‘java’ select title from books where id =2002 "

    下面是实现代码:

    public static void testUpS() {
    		String sql = "select * from books" + "where bid = 1 select * from cate"
    				+ " where name = 'java' select title"
    				+ " from books where id =2002 ";
    		// 先查找第二个select的位置
    		int i1 = sql.indexOf("select", 1);
    		int i2 = sql.lastIndexOf("select");
    		// 给select前面插入一个-,便于后面截取
    		StringBuffer sb = new StringBuffer(sql);
    		sb.insert(i1, "-");
    		sb.insert(i2,"-");
    		String [] str = (sb.toString()).split("-");
    		for (String ss : str) {
    			System.out.println(ss);
    		}
    		
    	}
    

    细细一看,不是很难的。
    欢迎关注公众号:雄雄的小课堂,哈哈哈~

  • 相关阅读:
    Lesson_strange_words6
    Lesson_strange_words3
    Lesson_strange_words4
    Lesson_strange_words1
    Lesson_strange_words2
    关于我们子页面
    关于我们页面
    走进龙门石窟子页面
    3.用户登陆注册
    2.项目初始化
  • 原文地址:https://www.cnblogs.com/a1111/p/12815830.html
Copyright © 2011-2022 走看看