[英]Length of a string in c# WinForm
I have a text box in my form and I want to check if the first char is equal to something, 我的表单中有一个文本框,我想检查第一个字符是否等于某个字符,
basically I want it to do this : 基本上我希望它这样做:
if(Textbox1.text.length(0) == "a")
{
do stuff
}
.length only returns an integer of length of the string. .length仅返回字符串长度的整数。 This will compare the first char with 'a'.
这会将第一个字符与“ a”进行比较。
if(Textbox1.text[0] == 'a')
Eh, are you looking for 嗯,你在找吗
if (Textbox1.Text.StartsWith("a")) {
// do stuff
...
}
you can do this by two ways... one i mentioned in your question's comment 您可以通过两种方式来实现此目的...一种是在您的问题的评论中提到的
second is 第二个是
if(myTextBox.Text[0] == 'B')
{
//do studd
}
try smething like this: 尝试这样的事情:
Textbox1.Text.StartsWith("a") ? do something : do something else;
and if it is not just about first character then try something like: 如果不仅是第一个字符,请尝试以下操作:
Textbox1.Text.Contains("a") ? do something : do something else;
if(textBox1.Text.Substring(0,1)==“ a”)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.