2010-03-29 91 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(" "));