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
.
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.
sure it is possible. Just take care that the textbox has some string longer than 3 characters
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
;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.