function ByteType(const S: string; Index: Integer): TMbcsByteType; mbSingleByte 单个字符 mbLeadByte 双字节字符的第一个字符 mbTrailByte 双字节字符的第二个字符procedure CheckChar(const S: string; Index: Integer); begin if ByteType(S, Index) = mbSingleByte then if S[Index] in ['0'..'9'] then //数字 else if S[Index] in ['a'..'z', 'A'..'Z'] then //英文字母 else //其他 else //双字节字符 end;
1、先判断右3个字符是否是数字,这好判断inttostr(Right(Str,3))不出现异常就行了;
2、从右第4个字符开始判断,若右第4个字符不是英文字符(无论大小写,ASCII码值的范围定一下),那就不用再判断了,字符串不合规则;
3、英文字符判断完了,就要判断接下的字符串是否是汉字了
就是这个思路了,这样的循环写起来也不是很复杂,执行起来也不占多长时间
mbSingleByte 单个字符
mbLeadByte 双字节字符的第一个字符
mbTrailByte 双字节字符的第二个字符procedure CheckChar(const S: string; Index: Integer);
begin
if ByteType(S, Index) = mbSingleByte then
if S[Index] in ['0'..'9'] then
//数字
else if S[Index] in ['a'..'z', 'A'..'Z'] then
//英文字母
else
//其他
else
//双字节字符
end;