在某些字符串的位置C#插入值? [英] C# Insert value in certain position in string?

查看:274
本文介绍了在某些字符串的位置C#插入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待从一个文本框的值时可以说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);

这篇关于在某些字符串的位置C#插入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆