StreamReader 的问题

发布于 2024-08-26 14:54:00 字数 833 浏览 14 评论 0原文

好吧,这就是我到目前为止所拥有的,

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

test 作为密码等命令让它更改频道,因为 CHANNEL = s;它用命令写出密码

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

这是写出IRC的唯一方法,所以有没有办法让“CHANNEL”仅作为文本的开头并且只是#lol,这样它就不会写出密码?

我希望你理解我的问题。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笔芯 2024-09-02 14:54:00

您可以在空格上拆分并获取第一项:

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

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);
葬心 2024-09-02 14:54:00
CHANNEL = s.Substring(0,s.IndexOf(" "));
CHANNEL = s.Substring(0,s.IndexOf(" "));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文