比如ER587
我需要判断前两位为字母,后三位为数字,是的话返回true
否则返回false
------解决方案--------------------------------------------------------
bool IsOk(string louzhu)
{
for(int index=0; index <louzhu.count&&index <5; index++)
{
if(index <2)
{
............
}
else if (index> =2)
{
.............
}
}
}
也可以用正则......
------解决方案--------------------------------------------------------
bool IsOk(string louzhu)
{
if (louzhu.Length <= 4)
{
return false;
}
for (int index = 0; index <= 4; index++)
{
if (index <= 1)
{
return ((louzhu[index] > = 'a ' && louzhu[index] <= 'z ') || (louzhu[index] > = 'A ' && louzhu[index] <= 'Z '));
}
else
{
return (louzhu[index] > = '0 ' && louzhu[index] <= '9 ');
}
}
}