在文本框的开头插入文本 [英] Insert text at the beginning of a text box
本文介绍了在文本框的开头插入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
单击按钮时,我需要在文本框的第一个字符中插入一些文本.
I need to insert some text as the first character of my textbox when a button is clicked.
这是我尝试过的:
private void btnInsert_Click(object sender, EventArgs e)
{
txtMainView.Text.Insert(0, "TEST");
}
当我单击按钮时,这无法插入文本.有人知道我在做什么错吗?
This fails to insert the text when I click the button. Anyone have an idea what I am doing wrong?
推荐答案
txtMainView.Text = txtMainView.Text.Insert(0, "TEST");
.NET Framework中字符串是不可变的,因此每个操作都会创建一个新实例,显然不会更改原始字符串本身!
Strings are immutable in .NET Framework so each operation creates a new instance, obviously does not change original string itself!
For more details on String
class see MSDN page Strings (C# Programming Guide)
这篇关于在文本框的开头插入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文