What I would like to do is take a string and return all possible substrings that are greater than length 2. So using the welcome example:
we
el
lc
co
me
wel
elc
lco
com
ome
welc
elco
lcom
come
and so on.....
The only way I could think to do it was something like this (totally untested):
for (int i = 0; i < word.Length; i++) //i is starting position
{
for (int j = 2; j + i < word.Length; j++) //j is number of characters to get
{
wordList.Add(word.SubString(i, j));
}
}
But I’m wondering if there a better way to do this (using LINQ possibly) that I don’t know about?
How’s this for a simple, readable approach?
It produces: