find the nth occurence of a substring in a string in java?

后端 未结 5 2122
南旧
南旧 2021-01-13 10:48

I have a string that is the complete content of an html page and I am trying to find the index of 2nd occurence of . Does anyone have any suggesti

5条回答
  •  庸人自扰
    2021-01-13 11:36

    Another good option for finding the Nth occurrence of a String is to use StringUtils.ordinalIndexOf() from Apache Commons:

    StringUtils.ordinalIndexOf("aabaabaa", "b", 2)  == 5
    

提交回复
热议问题