如何使用 Java 從字串中提取特定子字串?


您可以使用 String 類的 **substring()** 方法從 String 中提取子字串,為此方法,您需要傳遞所需子字串的起始索引和結束索引。

示例

即時演示

public class Substring {
   public static void main(String args[]) {

      String str = "Welcome to Tutorialspoint";
      String sub = str.substring(10, 25);
      System.out.println(sub);
   }
}

輸出

Tutorialspoint

更新於:2020-02-20

9K+ 瀏覽

開啟你的職業生涯

完成課程即可獲得認證

立刻開始
廣告
© . All rights reserved.