How to find the count of substring in java

前端 未结 4 1717
走了就别回头了
走了就别回头了 2021-01-01 02:43

I am trying to find the count of the substring in a big string of length 10000 characters. Finally I need to remove all the substring in it. example s = abacacac, subs

4条回答
  •  猫巷女王i
    2021-01-01 02:52

    For countung the substrings I would use indexOf:

    int count = 0;
    for (int pos = s.indexOf(substr); pos >= 0; pos = s.indexOf(substr, pos + 1))
        count++;
    

提交回复
热议问题