字符串的第一个字符可以通过以下操作检索吗?
MyString.ToCharArray[0]
字符串的第一个字符可以通过以下操作检索吗?
MyString.ToCharArray[0]
当前回答
或者你可以这样做:
MyString[0];
其他回答
也许这个会有帮助。我使用txtModel_Leave事件,然后创建方法来检测主文本框中的第一个字符。
private void txtMain_Leave(object sender, EventArgs e)
{
detectFirstChar();
}
private void detectFirstChar()
{
string mystr = txtModel.Text;
if (String.IsNullOrEmpty(txtModel.Text))
{
txtAwalan.Text = "";
}
else if (mystr.Substring(0, 1) == "F")
{
txtKategori.Text = "Finishing";
}
else if((mystr.Substring(0, 1) == "H"))
{
txtKategori.Text = "Half";
}
else
{
txtKategori.Text = "NONE";
}
}
试试这个,
字符串s1 =“好”; 字符串s = s1.Substring (0,1);
这是另一种方法:
string mystr = "hello";
MessageBox.show(mystr.Substring(0, 1));
或者你可以这样做:
MyString[0];
Mystring[0]应该足够了