Finding second occurrence of a substring in a string in Java

前端 未结 5 1847
孤城傲影
孤城傲影 2020-12-01 06:16

We are given a string, say, \"itiswhatitis\" and a substring, say, \"is\". I need to find the index of \'i\' when the string \"i

5条回答
  •  甜味超标
    2020-12-01 06:34

    i think a loop can be used.

    1 - check if the last index of substring is not the end of the main string.
    2 - take a new substring from the last index of the substring to the last index of the main string and check if it contains the search string
    3 - repeat the steps in a loop
    

提交回复
热议问题