美文网首页
提取字符串

提取字符串

作者: jinhm007 | 来源:发表于2019-02-20 22:53 被阅读0次

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();

    }

}

相关文章

网友评论

      本文标题:提取字符串

      本文链接:https://www.haomeiwen.com/subject/agzkyqtx.html