问题描述
我正在研究winapp。
这是一个机器人。
我想要添加和删除控制机器人的主人。
I'm working on a winapp.
It's a bot.
I want to add and delete masters who controls the bot.
//master add n remove
if (msg.Body != null && msg.Body.ToLower().StartsWith("addcon/"))
{
textBox4.Text = textBox4.Text + msg.Body.ToLower().Replace("addcon/", "#");
}
if (msg.Body != null && msg.Body.ToLower().StartsWith("delcon/"))
{
string str = msg.Body.ToLower().Replace("delcon/", "");
textBox4.Text.Replace(str + "#", "");
}
在上面的代码中,addcon / xyz命令被赋予bot来添加xyz到它的控制器,在textbox4中添加xyz#
和delcon / xyz用于从textbox4中删除xyz#
textbox4收集所有可通过远程命令控制机器人的机器人大师。
delcon无法正常工作。
任何帮助?
In the above code addcon/xyz command is given to bot to add xyz to its controller that adds xyz# in textbox4
and delcon/xyz coomand is given to delete xyz# from textbox4
textbox4 collects all ids of bot masters who can control the bot by remote commands.
The delcon is not working properly.
Any help?
推荐答案
string s1 = "Hello there!";
string s2 = s1;
s2.Replace("there", "World");
会导致更改发生在 s1
和 s2
因为它们都引用相同的字符串实例。
相反,它返回一个新的字符串,所以这个:
Would cause the change to happen to both s1
and s2
since they both reference the same string instance.
Instead, it returns a new string, so this:
string s1 = "Hello there!";
string s2 = s1;
s2 = s2.Replace("there", "World");
Console.WriteLine(s1);
Console.WriteLine(s2);
会打印
Would print
Hello there!
Hello World!
哪个更有用。
textbox4.Text = textBox4.Text.Replace(str + "#", "");
这篇关于如何从文本框中删除项目c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!