Insert value into a string at a certain position?

后端 未结 4 1178
我在风中等你
我在风中等你 2020-12-05 17:25

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

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-05 17:38

    If you have a string and you know the index you want to put the two variables in the string you can use:

    string temp = temp.Substring(0,index) + textbox1.Text + ":" + textbox2.Text +temp.Substring(index);
    

    But if it is a simple line you can use it this way:

    string temp = string.Format("your text goes here {0} rest of the text goes here : {1} , textBox1.Text , textBox2.Text ) ;"
    

提交回复
热议问题