【发布时间】:2018-01-06 03:51:47
【问题描述】:
我想根据以下条件将一个字符串拆分为多个字符串:
- 必须至少包含 2 个单词
- 每个单词必须相邻
例如: “你好,你好吗”我想分成:
- “你好,你好吗”
- “你好”
- “你好”
- “怎么样”
- “你好吗”
- “你是”
不能重复多次。
到目前为止,我得到的是:
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
我也想找其他人,需要一点帮助。
【问题讨论】: