我想做的是取一个字符串并返回所有长度大于2的可能子串。所以,使用welcome
这个例子:
we
el
lc
co
me
wel
elc
lco
com
ome
welc
elco
lcom
come
and so on.....
我能想到的唯一方法是像这样(未经测试):
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));
}
}
但我想知道是否有更好的方法来做到这一点(可能使用LINQ),而我不知道?
Distinct()
创建整个单词列表之后再进行此操作。 - Abe Miessler