[英]How to get first 3 characters of a textbox's text?
How do I get the first 3 characters of the text in a textbox?如何获取文本框中文本的前 3 个字符?
For example, textBox1.Text = "HITHEREGUYS"
例如, textBox1.Text = "HITHEREGUYS"
When I get the first 3 characters, it should show HIT
.当我得到前 3 个字符时,它应该显示HIT
。
string result = textBox1.Text.Substring(0,3);
使用子串
Text lower than 3 characters will throw an exception.少于 3 个字符的文本将引发异常。 So check text length first:所以首先检查文本长度:
string result = textBox1.Text.Length <= 3 ? textBox1.Text : textBox1.Text.Substring(0, 3);
这里基本上是你得到它的方式:
LEFT(textbox1.text, 3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.