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”。
答案 0 :(得分:0)
也许是这样的?
String input = TB.Text;
if (input.ToLowerInvariant().StartsWith("print: "))
{
String print = input.Substring(input.IndexOf(' ') + 1);
MessageBox.Show(print.Split(';')[0], "Console");
}