function haveNum(s:string):boolean; var i:integer; begin result:=false; for i:=1 to length(s) do if s[i] in ['0'..'9'] then begin result:=true; exit; end; end;
用ORD()函数,用一个FOR语句判断它是否属于字母
那如果我用定位的话,应该怎么来写呢? -------------------------------- 那样就把senfore(来而不往非礼也!) 的答案改写一下就可以了 function haveNum(s:string):integer; var i:integer; begin result:=false; for i:=1 to length(s) do if s[i] in ['0'..'9'] then begin result:=i; //返回数字所在的位置 exit; end; else result:=-1; //如果没有找到返回-1 end;
如果你只是想判断字串中是否存在0-9的数字,用senfore的方法就可以了 如果你想得到全部数字,用以下函数:function HaveNum(s: string): integer; var i: integer; lResult: string; begin i := -1; lResult := ''; for i := 1 to Length(s) do if s[i] in ['0'..'9'] then lResult := lResult + s[i]; Result := StrToInt(lResult); end;
var
i:integer;
begin
result:=false;
for i:=1 to length(s) do
if s[i] in ['0'..'9'] then begin
result:=true;
exit;
end;
end;
--------------------------------
那样就把senfore(来而不往非礼也!) 的答案改写一下就可以了
function haveNum(s:string):integer;
var
i:integer;
begin
result:=false;
for i:=1 to length(s) do
if s[i] in ['0'..'9'] then begin
result:=i; //返回数字所在的位置
exit;
end;
else
result:=-1; //如果没有找到返回-1
end;
如果你想得到全部数字,用以下函数:function HaveNum(s: string): integer;
var
i: integer;
lResult: string;
begin
i := -1;
lResult := '';
for i := 1 to Length(s) do
if s[i] in ['0'..'9'] then
lResult := lResult + s[i];
Result := StrToInt(lResult);
end;
IsCharAlpha和IsCharAlphaNumeric