在 Java 中使用點 (.)分割字串


假設以下內容是我們的字串。

String str = "This is demo text.This is sample text!";

要使用點分隔字串,請在 Java 中使用 split() 方法。

str.split("[.]", 0);

以下是完整示例。

示例

 即時演示

public class Demo {
    public static void main(String[] args) {
       String str = "This is demo text.This is sample text!";
       String[] res = str.split("[.]", 0);
       for(String myStr: res) {
          System.out.println(myStr);
       }
    }
}

輸出

This is demo text
This is sample text!

更新日期:2020-6-26

12K+ 瀏覽

啟動你的事業

完成課程以獲得認證

開始
廣告
© . All rights reserved.