提取字符串

package com.test.demo.test;

public class Test {

public  static Stringstr="column 1 \"sdfsdf\" type string 3";

    public static void main(String[] args) {

String tmpStr =str.replace("\"","");

        System.out.println(tmpStr);

        tmpStr=tmpStr.trim();

        int count =getSubLength(tmpStr," ");

        String [] strings = tmpStr.split(" ",count+1);

        if (strings.length>2)

System.out.println(strings[2]);

        if (strings.length>5)

System.out.println(strings[5]);

    }

/**

* 获取子串的个数

    * @param rawStr:原始字符串

    * @param subStr:子串

    * @return

    */

    public static int getSubLength(String rawStr,String subStr){

//int count=0;

//if (StringUtils.isBlank(rawStr)||StringUtils.isBlank(subStr)) return count;

        int length=rawStr.length()-rawStr.replace(subStr, "").length();

        return  length/subStr.length();

    }

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 7,604评论 0 3
  • 【程序1】 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔...
    开心的锣鼓阅读 8,571评论 0 9
  • 前言 最先接触编程的知识是在大学里面,大学里面学了一些基础的知识,c语言,java语言,单片机的汇编语言等;大学毕...
    oceanfive阅读 8,412评论 0 7
  • 【程序1】 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一...
    阿里高级软件架构师阅读 8,533评论 0 19
  • ❤第30篇文章 我们的故事到这儿就结束了 我也失去了唯一的读者和粉丝 以后或许不会在这儿写故事了 或许以后再也不会...
    学灰小女神阅读 1,267评论 0 1