如何使用 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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP