語音轉換截取N個文字進行轉換

語音轉換截取90個字以逗號隔開變成小句,多出來以少於90個字的最後一個逗號結束



//按90截句轉換
    public String[] fromjson90(String url) throws Exception {


        List<String> list = new ArrayList<String>();
        String[] changeContext =null;

        if (null != url && !"".equals(url)) {

            String contextparm = url;

            int pos =0;
            int nextstartindex=0;
            String tmpcp = contextparm;

            tmpcp = contextparm.substring(nextstartindex, 90+nextstartindex);

            while(tmpcp.length() >= 90)
            {

                pos = find_pos_lastindexof_from_90(tmpcp);


                nextstartindex+=pos;
                //changeContext[i++]=tmpcp.substring(0, pos);
                list.add(tmpcp.substring(0, pos));

                int len = contextparm.length();
                int end  =90+nextstartindex;
                 if(len <=end ){

                     tmpcp = contextparm.substring(nextstartindex, len);
                     }
                 else{
                     tmpcp = contextparm.substring(nextstartindex, end);
                 }

            }
            list.add(tmpcp);
            //changeContext[i++]=tmpcp;

               String[] s = new String[list.size()];
               changeContext = list.toArray(s);


            return changeContext;
        }
        return changeContext;
    }


    public int find_pos_lastindexof_from_90(String str90)
    {

        int lastpos;

        lastpos = str90.lastIndexOf(",");

        if(    lastpos == -1){
            lastpos = str90.length();
        }


        return lastpos;

    }

總結不好多多擔待,文章只單純個人總結,如不好勿噴,技術有限,有錯漏麻煩指正提出。本人QQ:373965070

發佈了49 篇原創文章 · 獲贊 79 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章