namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void compiler()
{
String print = "print Hello World";
String sP = print.Substring(print.IndexOf(' ') + 1);
MessageBox.Show(sP, "Console");
}
private void TB_TextChanged(object sender, EventArgs e)
{
}
private void runToolStripMenuItem_Click(object sender, EventArgs e)
{
compiler();
}
}
}
我对此进行了测试,并在开始时打印了hello world。 现在我只是想在文本框中尝试这样做,它可以读取我已输入" print"并且在空间之后的任何东西(例如:"打印"&那个空间就在那里)它将打印文本。我希望我为你说清楚! 所以基本上它说"打印Hello World"并且在开始时(当我调试时)它显示一条消息,说明Hello World,现在我试图让它读取文本框(TB),如果它说" print"然后打印出后面的内容。
答案 0 :(得分:1)
不太清楚你需要什么,但这可能会有所帮助?
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void compiler()
{
String print = TB.Text;
if (print.ToLowerInvariant().StartsWith("print ")
{
String sP = print.Substring(print.IndexOf(' ') + 1);
MessageBox.Show(sP, "Console");
}
}
private void TB_TextChanged(object sender, EventArgs e)
{
compiler();
}
private void runToolStripMenuItem_Click(object sender, EventArgs e)
{
compiler();
}
}
}