简体   繁体   中英

java - how many times char of string can get input inside another string

I need to count how many times one string can be inside another string.
Like if I have String one = "eloloel" , String two = "elo" , so it can be

  1. **elo**loel
  2. **e****l**ol**o**el
  3. **e**lo**l****o**el

if you can help with this problem please

I think we can use substring(int begIndex, int endIndex) inside for-loop that goes from 0 to length() . I am not sure though.

found if someone need it:P amm only need to make it recursion now if someone wan help:P hhh

public static int howmany(String word, String pattern) {
      int count = 0;
      int strLen = word.length();
      int patLen = pattern.length();
      for(int i = 1;i<=pattern.length();i++){
          for(int j = 1;j<=word.length();j++){
           if(str.charAt(strLen-j)==pattern.charAt(patLen-i)){
                 count++;
            }
           }
      }                       
      return count;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM