使用java中的String类操作复杂的字符串
生活随笔
收集整理的這篇文章主要介紹了
使用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);}}細細一看,不是很難的。
歡迎關注公眾號:雄雄的小課堂,哈哈哈~
總結
以上是生活随笔為你收集整理的使用java中的String类操作复杂的字符串的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大学生美术设计用笔记本电脑配置?
- 下一篇: 《白鹿原》金句摘抄(二)