function GetSubValue(S: string): String; const RexTop = '<$MD5>'; RexBottom = '</$MD5>'; var i, j : Integer; iCount: Integer; begin Result := ''; i := Pos(RexTop, S); if i > 0 then begin inc (i, Length(RexTop)); iCount := 1; for j := i to Length(S) - Length(RexBottom) do begin if Copy(S, j, Length(RexTop)) = RexTop then inc(iCount) else begin if Copy(S, j, Length(RexBottom)) = RexBottom then begin dec(iCount); if iCount = 0 then begin Result := Copy(S, i, j - i); break; end; end; end; end; end; end;...... ShowMessage (GetSubValue('fgjdguyr <$MD5>vs <$MD5>vsvsv </$MD5>vsv </$MD5>uyiryir')); ......
var str,sstr,estr:string; s,e:integer; begin str := 'fgjdguyr <$MD5>vs <$MD5>vsvsv </$MD5>vsv </$MD5>uyiryir'; estr := '</$MD5>'; sstr := '<$MD5>'; e := LastDelimiter(estr,str)-+Length(estr); s := Pos(sstr,str)+Length(sstr); str := Copy(str,s,e-s); ShowMessage(str); end;
修正一下var str,sstr,estr:string; s,e:integer; begin str := 'fgjdguyr <$MD5>vs <$MD5>vsvsv </$MD5>vsv </$MD5>uyiryir'; estr := '</$MD5>'; sstr := '<$MD5>'; e := LastDelimiter(estr,str)-Length(estr); s := Pos(sstr,str)+Length(sstr); str := Copy(str,s,e-s); ShowMessage(str); end;
fgjdguyr<$MD5>vs<$MD5>vsvsv</$MD5>vsv</$MD5>uyiryir
------------------------------------------- 我要从上面的一串字符中取出
vs<$MD5>vsvsv</$MD5>vsv
(首)<$MD5>中间值</$MD5>(尾)
中间值就是上面的vs<$MD5>vsvsv</$MD5>vsv,可是我写的程序不能写现这一点..他每一次都只是将vsvsv</$MD5>值取出,而不将最后的一个<$/MD5>
代码 Delete(memostr,1,Pos(Rextop,memostr));
liststr.Add(Copy(memostr,length(Rextop),Pos(Rexup,memostr)-length(Rexup)+1));
function GetSubValue(S: string): String;
const
RexTop = '<$MD5>';
RexBottom = '</$MD5>';
var
i, j : Integer;
iCount: Integer;
begin
Result := '';
i := Pos(RexTop, S);
if i > 0 then
begin
inc (i, Length(RexTop));
iCount := 1;
for j := i to Length(S) - Length(RexBottom) do
begin
if Copy(S, j, Length(RexTop)) = RexTop then
inc(iCount)
else begin
if Copy(S, j, Length(RexBottom)) = RexBottom then
begin
dec(iCount);
if iCount = 0 then
begin
Result := Copy(S, i, j - i);
break;
end;
end;
end;
end;
end;
end;......
ShowMessage (GetSubValue('fgjdguyr <$MD5>vs <$MD5>vsvsv </$MD5>vsv </$MD5>uyiryir'));
......
var
str,sstr,estr:string;
s,e:integer;
begin
str := 'fgjdguyr <$MD5>vs <$MD5>vsvsv </$MD5>vsv </$MD5>uyiryir';
estr := '</$MD5>';
sstr := '<$MD5>';
e := LastDelimiter(estr,str)-+Length(estr);
s := Pos(sstr,str)+Length(sstr);
str := Copy(str,s,e-s);
ShowMessage(str);
end;
str,sstr,estr:string;
s,e:integer;
begin
str := 'fgjdguyr <$MD5>vs <$MD5>vsvsv </$MD5>vsv </$MD5>uyiryir';
estr := '</$MD5>';
sstr := '<$MD5>';
e := LastDelimiter(estr,str)-Length(estr);
s := Pos(sstr,str)+Length(sstr);
str := Copy(str,s,e-s);
ShowMessage(str);
end;
谢谢回答。但是没有达到我的要求。我想让我写的程序像DELPHI开发工具一样,能够组合的转换里面的值.
就像这样
inttostr(strtoint('1'));
程序会找最中间的值