16,748
社区成员
发帖
与我相关
我的任务
分享
function find(source: pchar; find: pchar): string;
var
source_temp: PChar;
pos, len, current_pos, pos_temp: Integer;
pos_result, len_result: Integer;
I: Integer;
begin
source_temp := source;
current_pos := 0;
pos_temp :=0;
pos_result := 0;
len_result := 0;
while (Ord(source_temp^) <> 0) do
begin
pos_temp := current_pos;
for i := 0 to StrLen(find) do
begin
len := 0;
if (source_temp^ = find[i]) then
begin
pos := i;
while ((source[pos_temp] = find[pos] ) and (Ord(source [pos_temp]) <> 0) and (Ord(find[pos]) <> 0)) do
begin
Inc(pos_temp);
Inc(pos);
Inc(len);
end;
if (len> len_result) then
begin
len_result := len;
pos_result := i;
end;
end;
end;
Inc(current_pos);
Inc(source_temp);
end;
while(0 <>(len_result)) do
begin
Result := Result + find[pos_result];
Inc(pos_result);;
Dec(len_result);
end;
end;
function commanstring(shortstring: pchar; longstring: pchar): string;
var
J, I: Integer;
substring: array[0..255] of Char;
begin
result := '';
j := 0;
ShowMessage(IntToStr(Pos(shortstring, longstring)));
if(Pos(shortstring, longstring) > 0) then //strstr是从大串中找小串,找到后返回子串
Result := shortstring;
for i := strlen(shortstring)-1 downto 1 do //否则,开始循环计算
begin
for j := 0 to strlen(shortstring) - i do
begin
FillChar(substring, SizeOf(substring), #0);
Move(shortstring[j], substring[0], i);
if (substring = 'Edit1') then
Null;
if(Pos(substring, longstring) > 0) then
begin //strstr是从大串中找小串,找到后返回子串
Result := substring;
Exit;
end;
end;
end;
end;
function LCStrs(const A, B: string; LCSs: TStrings): Integer;
var
lsA, lsB, m, n, it, iCntA : Integer;
Mtx, OffsetsA : array of Integer;
pA, pB : PChar;
begin
lsA := Length(A)+1;
lsB := Length(B)+1;
Result := 0;
iCntA := 0;
SetLength(Mtx, lsA*lsB);
SetLength(OffsetsA, lsA);
pA := Pointer(A);
pB := Pointer(B);
for m:=lsA-2 downto 0 do
for n:=lsB-2 downto 0 do
begin
if(pA[m]<>pB[n])then Continue;
it := Mtx[(m+1)*lsB + n+1] + 1;
Mtx[m*lsB + n] := it;
if(it>Result)then
begin
Result := it;
iCntA := 1;
OffsetsA[0] := m;
end else
if(it=Result)then
begin
OffsetsA[iCntA] := m;
Inc(iCntA);
end;
end;
if(Assigned(LCSs))then
for m:=iCntA-1 downto 0 do
LCSs.Add(Copy(A, OffsetsA[m]+1, Result));
end;