javascript - get all the possible substrings in the order -


there many solutions finding possible substrings. have tried this php solution.

however have specific requirements. need generate substrings using characters in order. ex: if given string is: 'abcde'

then possible combinations are: 'abcd', 'abc', 'acde', 'acd', 'ade', 'bcde', 'bcd', 'bde' , 'cde'

(length of substring should more 2, of-course simple achieve. )

not allowed combinations: 'edcba', 'dba', 'ecba', 'aabb' etc

can 1 suggest how can achieve this? either php or javascript solutions acceptable.

try below:

 function getsubstring($str, $length = 3)  {     $len = strlen($str);     $arr = [];      for($i = 0; $i < $len; $i++)     {          $start = $i + 1;         $end = $len - 1;         while($start <= $end)         {             $l = $length - 1;             while($l + $start <= $len )             {                 $es =  $str[$i].substr($str, $start, $l);                 if ($str != $es)                     $arr[] = $es;                 $l += 1;             }             $start += 1;         }     }      return $arr;   } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -