var i,j : integer;
s : string;
s := '';
for i := 0 to Length(str)- 1 do
begin
if str in ['0'..'9','-'] then
begin
repeat
j := i;
s := s + str[j];
Inc(j);
until str[j] not in ['0'..'9','-'];
end;
end;
随便写了写,你看着改一下。
方法是有点笨了,还算可以。
function GetTelNumPos(strContent,strEnum: string;var iEnd: Integer; var iPos: Integer; bFind: Boolean = True): Boolean;
var
iLength, i: Integer;
begin
Result := False;
for i := iEnd downto 1 do
begin
iPos := Pos(strContent, strEnum);
if bFind then
begin
if iPos > 0 then
begin
iPos:=i;
Result := True;
Break;
end;
end
else
begin
if iPos = 0 then
begin
iPos:=i;
Result := True;
Break;
end;
end;
end;
end;
function GetTelFromText(var strContent: string; var strTel: string;const strEnum:String): Boolean;
var
i, iLength, iBegin, iEnd: Integer;
strTmp: string;
begin
Result := False;
// strEnum:='0123456789-,.() '; 电话中允许出现在字符
strContent := Trim(strContent);
iEnd:=0;
iBegin:=0;
iLength := Length(strContent);
if GetTelNumPos(strContent,strEnum , iLength, iEnd) then
if GetTelNumPos(strContent,strEnum, iEnd, iBegin, False) then
begin
strTmp := Copy(strContent, iBegin+1, iEnd-iBegin);
if Length(strTmp) >= 7 then //电话至少要有七位数
begin
strTel := strTmp;
Result := True;
end;
end;
end;