返回字符串的特定子字符串的第一个字母的索引 [英] 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.
例如,给定字符串"itiswhatitis"和子字符串"is",输出应为2.
For example, given a string "itiswhatitis" and the substring "is", the output should be 2.
推荐答案
您可以按以下方式使用
int indexOf(String str)
来自示例字符串.
String s ="itiswhatitis";
int index = s.indexOf("is");
这篇关于返回字符串的特定子字符串的第一个字母的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文