将值插入字符串中的某个位置?
问题描述:
我要在文本框中放置一个值,让它在字符串temp变量中的某个位置说 12。然后,我想在该值之后加上另一个值 10,但要在中间加上一个:,就像时间一样。
i'm looking to place a value from a text box lets say "12" to a certain place in a string temp variable. Then I want to place another value after that say "10" but with a : in between like a time. Both come from Text boxes and are validated so they can only be numbers.
答
您不能修改字符串;它们只能是数字。他们是一成不变的。您可以改为:
You can't modify strings; they're immutable. You can do this instead:
txtBox.Text = txtBox.Text.Substring(0, i) + "TEXT" + txtBox.Text.Substring(i);