我希望根据以下条件将字符串拆分为多个字符串:
我目前的代码如下:
它输出如下内容:
- 必须是至少两个单词在一起
- 每个单词必须紧挨着
- "hello how are you"
- "hello how are"
- "hello how"
- "how are"
- "how are you"
- "are you"
我目前的代码如下:
string input = "hello how are you";
List<string> words = input.Split(' ').ToList();
List<string> inputs = new List<string>();
string temp = String.Empty;
for (int i = 0; i < words.Count; i++)
{
temp += words[i] + " ";
if (i > 0)
{
inputs.Add(temp);
}
}
它输出如下内容:
hello how
hello how are
hello how are you
我希望能得到其他人的帮助,并且需要一点协助。