如何在文本框中获取单词的行?

How can I get the line of an word in a textbox?

你能解决这个问题吗?我不知道它应该如何工作,但也许你知道。

我有两个文本框。在左边我有这个内容:

莫, 28.09.15

莫, 28.09.15

在右侧,我希望将内容 "English" 放在与第二个 "Mo," 相同的行中。可能吗?

感谢您的帮助和时间。 迪特

您可以检索文本框中的值

 TextBox objTextBox = (TextBox)sender;
    string theText = objTextBox.Text;

if(sender is TextBox) {
 var text = (sender as TextBox).Text;
}

这会在 "Di" 前面添加 "English"。我想这就是你要问的。

        string text = textBox2.Text;
        text = text.Insert(text.IndexOf("Di"), "English ");
        textBox2.Text = text;

但是如果您正在使用日期并尝试根据地区格式化它们,那么您应该查看 DateTime class。

这是另一种基本方法:

        List<string> lines = new List<string>(textBox1.Lines);
        for(int i = 0; i < lines.Count; i++)
        {
            // check for some condition
            if (lines[i].StartsWith("Di"))
            {
                // modify the line somehow
                lines[i] = lines[i] + ", " + textBox2.Text;
                break; // optionally break?...or modify other lines as well?
            }
        }
        textBox1.Lines = lines.ToArray(); // update the textbox with the new lines