簡體   English   中英

如何在文本框中獲取單詞的行?

[英]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 類。

這是另一種基本方法:

        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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM