如何分割帶轉義符的分隔符?


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

更新於: 26-Feb-2020

330 瀏覽

開啟您的 職業生涯

完成課程,獲得認證

開始使用
廣告
© . All rights reserved.