<分区>
我想将句子的一部分(这是一个字符串)保存到另一个字符串中。
例如:
String s = "到 1889 年,由于问候语和电话之间的联系,中央电话交换台接线员被称为 'hello-girls' "
我想将“By 1889, central telephone exchange operators were known as”保存到一个字符串中
和
“hello-girls'因打招呼和电话的联想”变成了另一种。
怎么做?
<分区>
我想将句子的一部分(这是一个字符串)保存到另一个字符串中。
例如:
String s = "到 1889 年,由于问候语和电话之间的联系,中央电话交换台接线员被称为 'hello-girls' "
我想将“By 1889, central telephone exchange operators were known as”保存到一个字符串中
和
“hello-girls'因打招呼和电话的联想”变成了另一种。
怎么做?
最佳答案
尝试:
int index = s.indexOf("'hello-girls'");
System.out.println(s.substring(0, index ));
System.out.println(s.substring(index));
输出:
By 1889, central telephone exchange operators were known as
'hello-girls' due to the association between the greeting and the telephone
文档:
关于java - Java 中的子字符串 - 如何断开句子并另存为不同的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31329795/