2010-03-29 90 views
1

好吧所以这里是我到目前为止,麻烦与StreamReader的

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的唯一途径所以有仅是文本的开始方式的“通道”,只是#lol所以它不写出密码写出密码?

我希望你能理解我的问题。

回答

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); 
0
CHANNEL = s.Substring(0,s.IndexOf(" "));