本文介绍了如何在给定两个索引的字符串中找到所有连续的子串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

How do I find all consecutive substrings in a string given two indices





我是什么尝试过:





What I have tried:

def all_possible_substring(string, start, end){
  for ( i : [start:end+1] ){ // from index start to end
    for ( j : [i:end+1] ){ // from index i to end
      println( string[i:j]) // splice the string from i,j and print
    }
  }
}
all_possible_substring( "abcdef" , 0, 2) // test it off

推荐答案

def all_possible_substring(string, start, end){
  WHILE (end < string.length - 1)
      println( string[start:end])
      start += 1
      end += 1
  }
}
all_possible_substring( "abcdef" , 0, 2) // test it off





是的,我知道这不是PHP,但逻辑是一样的。



Yes, I know this is not PHP, but the logic is the same.


这篇关于如何在给定两个索引的字符串中找到所有连续的子串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 15:55