好的,所以这就是我到目前为止所做的,
List<string> lines = new List<string>();
using (StreamReader r = new StreamReader(f))
{
string line;
while ((line = r.ReadLine()) != null)
{
lines.Add(line);
}
}
foreach (string s in lines)
{
NetworkStream stream = irc.GetStream();
writer.WriteLine(USER);
writer.Flush();
writer.WriteLine("NICK " + NICK);
writer.Flush();
writer.WriteLine("JOIN " + s);
writer.Flush();
string trimmedString = string.Empty;
CHANNEL = s;
}
不幸的是,当我的IRC假人进入一个设置了密码的房间时,它会写出密码,如果我用#lol test等命令改变频道
测试是密码,因为CHANNEL = s;它用命令
写出密码writer.WriteLine("PRIVMSG " + CHANNEL + " :" + "Hello");
这是写出IRC的唯一方法所以有没有办法让“CHANNEL”只是文本的开头而只是#lol所以它不会写出密码?
我希望你能理解我的问题。
答案 0 :(得分:2)
您可以拆分空格并选择第一项:
CHANNEL = s.Split(' ')[0];
这会导致{ "#lol", "test" }
,但理想情况下会事先检查:
string input = "#lol test";
string channel = "";
string key = "";
if (input.Contains(" "))
{
string[] split = input.Split(' ');
channel = split[0];
key = split[1];
}
else
{
channel = input;
}
Console.WriteLine("Chan: {0}, Key: {1}", channel, key);
答案 1 :(得分:0)
CHANNEL = s.Substring(0,s.IndexOf(" "));