セットの文字列部分の最初と最後の文字列部分を考慮すると、その文字列の傍受の組成を決定するために他の文字列を傍受するためにそれらを使用して、開始と文字列の文字列の末尾(ワイルドカードをサポートする必要が、一つだけのアスタリスクは任意の文字を表しサポートしていますそして、文字列の途中にアスタリスクのみ)

パッケージビルダー; 


輸入はjava.util.ArrayList;
輸入はjava.util.List; 

パブリック クラスのテスト{
     公共 静的 ボイドメイン(文字列[]引数){
         // 下面期望输出[jgajgaagi; aghuhagajagg ;; G、ga23ty1] 
        文字列str = "agaggaga <; agpjgajgaagi; aghuhagajagg ;; gakagkogagpga23ty1ak1hg" 
        文字列のオープン =「*のGP」
        文字列近い =「AK」

      
        // 下面期望输出[AG、PJ、I; aghuha、G ;;、KO] 
        列STR2 = "agaggaga <; agpjgajgaagi; aghuhagajagg ;; gakagkogaga23ty11hg" 
        文字列open2 = "AG"
        文字列のclose2 = "GA" 


        一覧 <文字列> midList = getMidList(STR、オープン、クローズ)。
        リストの<string> midList2 = getMidList(STR2、open2、close2)。

        System.out.println(midList)。
        System.out.println(midList2)。

    } 

    公共の 静的リストの<string> getMidList(文字列str、オープン文字列、文字列近い){ 
        リストの<string> retList = 新規のArrayList <>(); // 存储结果
        場合(isEmpyty(STR)|| isEmpyty(開く)|| isEmpyty(近い)){
             戻りretListと、
        } 

        リスト<ストリング> openList = のgetString(STR、オープン)。
        リストの<string> closeList = のgetString(STR、近いです)。
        もし(!openList.isEmpty()&& closeList.isEmpty()){ 
            文字列のTEMP = NULL ; 
            アウター:
            のための(文字列プレ:openList){
                 ため(文字列サブ:closeList){
                     int型 I = str.indexOf(PRE)。
                    もし(I == -1 ){
                         続けるアウター。
                    } 
                    、I = I +は)(pre.lengthします。
                    STR = str.substring(I)。// 去掉头
                    INT DD = str.indexOf(サブ)。
                    もし(DD == -1 ){
                         続けます
                    } 
                    TEMP = STR。
                    retList.add(str.substring( 0 、DD))。
                    STR = temp.substring(DD + sub.length())。
                    壊れ外側; 
                } 

            } 
        } 
            ながら){
                 場合ヌル == STR || retList.isEmpty()){
                     破ります
                } 
                openList = のgetString(STR、オープン)。
                closeList = のgetString(STR、近いです)。
                もし(openList.isEmpty()|| closeList.isEmpty()){
                     ブレーク
                } 
                文字列TEMP2 = NULL ; 
                アウター:のために{(openListストリングPRE)
                     のための(文字列サブ:closeList){
                         int型 I =str.indexOf(PRE)。
                        もし(I == - 1 ){
                             続けるアウター。
                        } 
                        、I = I +は)(pre.lengthします。
                        STR = str.substring(I)。// 去掉头
                        INT DD = str.indexOf(サブ)。
                        もし - (1 DDの== ){
                             続けます
                        } 
                        TEMP2 = STR。
                        retList.add(str.substring( 0 、DD))。
                        STR = temp2.​​substring(DD + sub.length())。
                    } 

                } 

            } 

            戻りretList。

    } 












    パブリック 静的  ブールisEmpyty(文字列str){
         場合ヌル。== STR || STR == "" || str.trim()の長さ()== 0 ){
             戻り 
        } 
        を返す 
    } 


    公共の 静的リストの<string> のgetString(文字列str、文字列オープン){ 
        String []型スプリット = open.split( "\\ *" )。
        一覧 <文字列>リスト= 新しい ArrayListを<> もし();
        (split.length == 1 ){ 
            ストリングプリ =スプリット[0 ]。
            もし(!str.indexOf(PRE)= - 1 ){ 
                list.add(PRE)。
            } 
            戻りリスト。
        } 
        であれば(split.length> = 3 ){
             戻りリスト。
        } 
        ストリングS1 =スプリット[0 ]。
        ストリングS2 =スプリット[1 ]。
        文字列のTEMP = nullを一方、){
             int型 I = str.indexOf(S1)。
            もし(I == - 1 ){
                 破ります
            } 
            int型 I2 = str.indexOf(S2)。
            もし - (1 I2の== ){
                 破ります
            } 
            TEMP = STR。
            list.add(str.substring(I、I2 + s2.length()))。
            STR = temp.substring(I2 + s2.length())。
        } 

        戻りリスト。
    } 





}

 

おすすめ

転載: www.cnblogs.com/yangxiaohui227/p/11344806.html