16,748
社区成员
发帖
与我相关
我的任务
分享
procedure LeiStrsCustom(strIn:TStrings;strOut:TStrings;iType:integer);//0:不连,2:2号连,3:3号连
var
i:integer;
begin
strOut.Clear;
for i:=0 to strIn.Count-1 do
begin
if StrLeiCnt(strIn.Strings[i])=iType then
strOut.Add(strIn.Strings[i]);
end;
end;
//使用
LeiStrsCustom(strs,Memo1.Lines,3);
function StrLeiCnt(str:string):integer;
var
iCnt:integer;
begin
iCnt:=Ord(StrToInt(str[2])-StrToInt(str[1])=1)
+Ord(StrToInt(str[3])-StrToInt(str[2])=1)
+Ord((str[1]='9') and (str[2]='0'))
+Ord((str[2]='9') and (str[3]='0'));
if iCnt<>0 then
inc(iCnt);
Result:=iCnt;
end;
function StrLeiCnt(str:string):integer;
var
iCnt:integer;
begin
iCnt:=Ord(StrToInt(str[2])-StrToInt(str[1])=1)+Ord(StrToInt(str[3])-StrToInt(str[2])=1);
if iCnt<>0 then
inc(iCnt);
Result:=iCnt;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
i:integer;
strs:TStringList;
str2:string;
begin
strs:=TStringList.Create;
strs.Add('128');
strs.Add('296');
strs.Add('123');
for i:=0 to strs.Count-1 do
Memo1.Lines.Add(strs.Strings[i]+','+IntToStr(StrLeiCnt(strs.Strings[i]))+'连号');
strs.Free;
end;