一个字符串,我怎样判断它的内容是否符合我的要求? (50分)

  • 主题发起人 Restart1
  • 开始时间
R

Restart1

Unregistered / Unconfirmed
GUEST, unregistred user!
我有一个字符串B,现在我想知道它是否只是一个2位整数。怎么判断呢
 
1.if Length(A)=1 then
if (a[1] in (['a'..'z']) or (a[1] in ['A'..'Z']) then
want you do.
2. if Length(B)=2 then
begin
try
n :=strtoint(B);
if n>9 then
want you do.
except
end;
end
 
if (Length(A)=1) and (A[1] in ['a'..'z', 'A'..'Z']) then

if (Length(A)=2) then
if (A[1] in ['0'..'9']) and (A[2] in ['0'..'9']) then
 
var
i:integer;
begin
try
i:=strtoint(edit1.text);
if not ((i >= 10) and (i < 100)) then
showmessage('error');
except
showmessage('error');
end;
end;
 
Result := Length(A)=1;
if Result then
Result := A[1] in [a..z,A..Z];

i := StrToIntDef(B,0);
Result := (i>9) and (i<100);
 
if(length(B)<>2)then//如果不是两位
begin
...//do you want
end
else //如果是两位,判断是不是数字
begin
if(B[1] in ['0'..'9'])and(B[2] in ['0'..'9'])then
begin
...//do you want
end;
end;
 
这么热闹,来晚了。
 
try
if length(B)<>2 then
begin
showmessage('no');
exit;
end;
i:=strtoint(B)
except
showmessage('no');
end;
 
strtoint() >=10 and <=99
 
晚了一布
 
顶部