如何分解帶有轉義分隔符的字串?


String 類的 split(String regex) 方法可根據給定的正則表示式的匹配項分解此字串。

示例

現場演示

public class Sample{
   public static void main(String args[]){
      String s = "|A|BB||CCC|||";
      String[] words = s.split("\|");
      for (String string : words) {
         System.out.println(string);
      }
   }
}

輸出

A
BB
CCC

更新於: 2020 年 2 月 26 日

333 次瀏覽

開啟您的 職業生涯

完成課程取得認證

開始
廣告
© . All rights reserved.