如何使用 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