【发布时间】:2018-08-20 01:33:58
【问题描述】:
嗨,我有一个字符串,我想查找特定单词的索引,但字符串的 indexOf() 方法返回子字符串索引。例如:
String example = "7. Political career He was first elected as an alderman for St.";
int index = example.indexOf("as");
但此方法返回单词“was”中子字符串“as”的索引,而不是单词“as”的索引。
【问题讨论】:
-
返回此字符串中第一次出现指定子字符串的索引。 docs.oracle.com/javase/7/docs/api/java/lang/…
-
谢谢,我应该如何解决这个问题?