首先判断你的字符串mystring长度是否大于6.写程序要严谨。
if(mystring.Length>6)
{
string resultString=mystring.Substring(mystring.Length-6,6);
再判断resultString.
if(resultString==".shtml")
{
成功
}
else
{
失败
}
}
else
{
失败
}
string result=mystring.Substring((int i=mystring.Length)-7,6);
if(i>6){
if(resultString=="shtml")
{
MessageBox.Show("成功");}
else
{
MessageBox.Show("失败");
}
} else{MessageBox.Show("少于6位失败");
}
mystring.EndsWith(".shtml");
EndsWith是一个检查字符串是不是以指定的字符串结尾的方法(bool)
string str=mystring.SubString(mystring.LastIndexOf(".")+1);
if(str=="shtml")
return true;
else
return false;
用.EndsWith()方法更好一些吧。