问题
I am given a string and I wish to find out the index of the first character of a substring of that string whenever it appears the very first time in the parent string.
For example, given a string "itiswhatitis" and the substring "is", the output should be 2.
回答1:
You can use as below
int indexOf(String str)
from your example string.
String s ="itiswhatitis";
int index = s.indexOf("is");
回答2:
"itiswhatitis".indexOf("is")
Try this
回答3:
public static void main(String[] args) {
int index = "itiswhatitis".indexOf("is");
System.out.println(index);
}
回答4:
String str="itiswhatitis";
int index=str.indexOf("is");
来源:https://stackoverflow.com/questions/19025654/return-index-of-the-first-letter-of-a-specific-substring-of-a-string