java - How would I check if a part of a string equals another string of unknown length? -


        for(int j = 1;j<filearray.size();j++) {             if(str.contains(filearray.get(end+j))) {              }         } 

(assume end number such 30). goal of part when having window length of 30 , filearray size > 30, check if theres after index 30 matches whatever inside window. ex: "i eat piesss aaaabbbbpiesssbbbb" starting beginning of string add first 17 characters arraylist called window. check rest of string starting right after window see if there's matches. space doesnt match add output. keep checking see "piesss" matches. replace second "piesss" wherever first "piesss" occurs.

so right im using filearray.get(end+j) check if there's matches within string(str) except doesn't work. there way fix code segment?

the replacement part of question still unclear. reasoning use arraylist. i've written code 5 character window search match after splitting string provided. note how 30 , 17 values gave nothing ever matched (see commented out code). tweaked values matches can found.

public static void main(string[] args) {                  //          1         2         3                     //012345678901234567890123456789012345678   <- shows index      string test = "i eat piesss aaaabbbbpiesssbbbb"; //    int first = 17; //    int end = 30;      int first = 20;     int end = 37;      string firsthalf = test.substring(0, first);     string secondhalf = test.substring(first, end);      int matchsize = 5;      (int = 0; + matchsize < secondhalf.length() ; i++)     {         string window = secondhalf.substring(i, + matchsize);         if ( firsthalf.contains(window) )         {             system.out.println(window);         }     }     system.out.println("done searching."); } 

displays:

piess iesss done searching. 

if isn't meant please edit question make needs clear.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -