I want to split a string into multiple strings based on the following criteria:
- It has to be minimum 2 words together
- Each word must be next to each other
For example: "hello how are you" I want to split into:
- "hello how are you"
- "hello how are"
- "hello how"
- "how are"
- "how are you"
- "are you"
Can't repeat multiple times.
What I got so far is this:
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);
}
}
It outputs the following:
hello how
hello how are
hello how are you
I want to get the others too and need a little help with that.