Computing All The Possible Substrings of a Given String [duplicate]
问题 Possible Duplicate: How to find all substrings of a string in PHP Find all subsets of a list How can I compute all the possible substrings of a string? For example given a string ABCDE. All its possible substrings will be A, B, C, D, E, AB, BC, CD, DE, ABC, BCD, CDE, ABCD, BCDE, ABCDE Thanks! A pseudocode will be highly appreciated. :D 回答1: Just use two for-loops: generate substrings(string): for start in [0,1,...,string.length-1]: for end in [start,...,string.length-1]: yield string[start..