【发布时间】:2016-01-11 08:43:25
【问题描述】:
所以,我有一个如下所示的文本文件:
[hello]Hi
[hello]welcome back
[hello]Hello sir
[goodbye]goodbye sir
[goodbye]until next time
...
下面是部分代码:
string[] responseLines = File.ReadAllLines(@"responses.txt");
Random rand = new Random();
string response;
case "hello":
chatBox.Items.Add(Me);
response = responseLines[rand.Next(responseLines.Length)];
JARVIS.SpeakAsync(response);
chatBox.Items.Add("Jarvis: " + response);
break;
问题是我只想找到包含[hello] 的行,然后随机选择其中之一。
【问题讨论】: