【问题标题】:return index of the first letter of a specific substring of a string返回字符串的特定子字符串的第一个字母的索引
【发布时间】:2013-10-02 06:27:23
【问题描述】:

我得到一个字符串,我希望找出该字符串的子字符串的第一个字符的索引,只要它第一次出现在父字符串中。

例如,给定字符串“itiswhatitis”和子字符串“is”,输出应为 2。

【问题讨论】:

标签: java string substring indexof


【解决方案1】:

你可以如下使用

int indexOf(String str)

来自您的示例字符串。

String s ="itiswhatitis";

int index = s.indexOf("is");
【解决方案2】:
"itiswhatitis".indexOf("is")

试试这个

【解决方案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");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-17
      相关资源
      最近更新 更多