如何让我的打印命令在分号后停止打印?

时间:2015-06-08 01:23:17

标签: c#

namespace TextEditor
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void code()
    {
        String input = TB.Text;

        if (input.ToLowerInvariant().Contains("print: "))
        {
            String print = input.Substring(input.IndexOf(' ') + 1);
            MessageBox.Show(print, "Console");
        }
    }

    //When about is clicked
    private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Personal stuff", "IDK");
    }

    //Reset text when new is clicked
    private void newToolStripMenuItem_Click(object sender, EventArgs e)
    {
        TB.Text = "";
    }

    private void runToolStripMenuItem_Click(object sender, EventArgs e)
    {
        code();
    }
}
}
  

我怎么做到它只是读取“print:”和分号之间的什么?就像我输入(在文本框(TB)中)“打印:Hello World;”在下一行我输入“忽略这个”,它将出现在消息框中,只说“Hello World”。

1 个答案:

答案 0 :(得分:0)

也许是这样的?

 String input = TB.Text;
       if (input.ToLowerInvariant().StartsWith("print: "))
        {
            String print = input.Substring(input.IndexOf(' ') + 1);

            MessageBox.Show(print.Split(';')[0], "Console");
        }