[英]return index of the first letter of a specific substring of a string
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. 例如,给定字符串“ itiswhatitis”和子字符串“ is”,输出应为2。
You can use as below 您可以如下使用
int indexOf(String str)
from your example string. 从您的示例字符串。
String s ="itiswhatitis";
int index = s.indexOf("is");
"itiswhatitis".indexOf("is")
尝试这个
public static void main(String[] args) {
int index = "itiswhatitis".indexOf("is");
System.out.println(index);
}
String str="itiswhatitis";
int index=str.indexOf("is");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.