return index of the first letter of a specific substring of a string

北战南征 提交于 2020-01-16 01:28:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!