1

Alright so here is what I have so far,

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;
}

Unfortunately when my IRC dummy enters a room with a password set it writes out the password, if I make it change channel with a command such as #lol test

test being the password, since CHANNEL = s; it writes out the password with the command

writer.WriteLine("PRIVMSG " + CHANNEL + " :" + "Hello");

That is the only way to write out to IRC so is there a way for the "CHANNEL" to only be the start of the text and just #lol so it doesn't write out the password?

I hope you understand my problem.

4

2 回答 2

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);
于 2010-03-29T18:28:06.927 回答
0
CHANNEL = s.Substring(0,s.IndexOf(" "));
于 2010-03-29T18:28:25.440 回答