可以使用 Java 中的 split() 方法根据换行符拆分文本块。例如:

String text = 'This is the first line.
This is the second line.
This is the third line.';
String[] lines = text.split('\n');

for (String line : lines) {
    System.out.println(line);
}

输出结果为:

This is the first line.
This is the second line.
This is the third line.

在这个例子中,我们首先定义了一个包含多行文本的字符串。然后,我们使用 split() 方法将字符串根据换行符拆分成一个字符串数组。最后,我们使用 for 循环遍历数组并打印每一行文本。

Java 使用 split() 方法根据换行符拆分文本块

原文地址: https://www.cveoy.top/t/topic/fWoo 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录