Delphi 获取URL中的关键字中的部分

function CenterStr(Src: string; Before, After: string): string;
var
  Pos1, Pos2: WORD;
begin
  Pos1 := Pos(Before, Src);
  Pos2 := Pos(After, Src);
  if (Pos1 = 0) or (Pos2 = 0) then    //如果src中没有B串和A串
  begin
    Result := '';
    Exit;
  end;
  Pos1 := Pos1 + Length(Before);      //句1.B串起始位+B串的长度
  if Pos2 - Pos1 = 0 then
  begin
    Result := '';
    Exit;
  end;
  Result := Copy(Src, Pos1, Pos2 - Pos1);  // 从B串后的第一字符开始复制
  //此函数的作用实际上就是取得B\A两串之得的字符串,适用于BA两串已知, 要取的串由用户确定的情况
end;

用法
var
   uRL,qc,hc,syc:string;
begin
  URL:='<sortlist>id</sortlist>';
   qc:='<sortlist>';
   hc:='</sortlist>';
   syc:=CenterStr(ur,qc,);
end;

posted @ 2012-08-16 18:10  逍遥豆子  阅读(408)  评论(1)    收藏  举报