我想从文本框中放置一个值,让"12"表示字符串临时变量中的某个位置.然后我想在说"10"之后放置另一个值,但是之间有一个:介于两者之间.两者都来自文本框并经过验证,因此它们只能是数字.
and*_*rsh 62
如果您只想在字符串中的某个位置插入值,可以使用String.Insert方法:
public string Insert(
int startIndex,
string value
)
Run Code Online (Sandbox Code Playgroud)
例:
"abc".Insert(2, "XYZ") == "abXYZc"
Run Code Online (Sandbox Code Playgroud)
Meh*_*dad 32
你不能修改字符串; 他们是不变的.你可以这样做:
txtBox.Text = txtBox.Text.Substring(0, i) + "TEXT" + txtBox.Text.Substring(i);
Run Code Online (Sandbox Code Playgroud)
如果您有一个字符串,并且您知道要将两个变量放在字符串中的索引,则可以使用:
string temp = temp.Substring(0,index) + textbox1.Text + ":" + textbox2.Text +temp.Substring(index);
Run Code Online (Sandbox Code Playgroud)
但如果它是一个简单的线,你可以这样使用它:
string temp = string.Format("your text goes here {0} rest of the text goes here : {1} , textBox1.Text , textBox2.Text ) ;"
Run Code Online (Sandbox Code Playgroud)