views:

71

answers:

2

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.

+2  A: 

You can split on a space and take the first item:

CHANNEL = s.Split(' ')[0];

This would result in { "#lol", "test" } although ideally would check beforehand:

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