[英]C# Is it possible to get the two input textbox values in one textbox without overwriting the first input value of textbox?
I've been searching this for a while but i didn't get any information about this, so i don't know if it is possible or not.我已经搜索了一段时间,但我没有得到任何有关此的信息,所以我不知道是否可能。 Here's what i'm trying to achieve.这就是我想要实现的目标。 Any suggestions there ?有什么建议吗? Thank you谢谢
Example:例子:
当然,这是可能的:
Textbox3.Text = Textbox1.Text.Substring(0,3)+Textbox2.Text
Another way to do it if there's a possibility that textBox1.Text
is less than 3 characters is to use the Take
method to take up to 3 characters from the string (treating is as an array of characters), then use Concat
to put those characters back into a string, and finally concatenate it with textBox2.Text
.如果textBox1.Text
可能少于 3 个字符,另一种方法是使用Take
方法从字符串中提取最多 3 个字符(处理为字符数组),然后使用Concat
放置这些字符回到一个字符串,最后将它与textBox2.Text
连接起来。
textBox3.Text = string.Concat(textBox1.Text.Take(3)) + textBox2.Text;
It's a little "wordy", but will prevent exceptions from being thrown if textBox1
contains fewer than 3 characters.这有点“罗嗦”,但如果textBox1
包含少于 3 个字符,则会防止抛出异常。
sure it is possible.肯定有可能。 Just take care that the textbox has some string longer than 3 characters请注意文本框有一些长度超过 3 个字符的字符串
string processedText;
int NoOfChars = 3;
if (textBox1.Text.Length >= NoOfChars)
processedText = textBox1.Text.Substring(0, NoOfChars);
else
processedText = textBox1.Text;
textBox3.Text = processedText + textBox2.Text
; ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.