How to find the count of substring in java

前端 未结 4 1708
走了就别回头了
走了就别回头了 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条回答
  •  不思量自难忘°
    2021-01-01 02:52

    To count the matching substring

    System.out.println(s.split(substr, -1).length-1);
    

    To get replaced string- you can use following code

    System.out.println(Pattern.compile(s).matcher(substr).replaceAll(""));

提交回复
热议问题