⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unitlib.pas

📁 Delphi6分布式开发例程12 )
💻 PAS
字号:
unit Unitlib;

interface

uses SysUtils;

type
   StrArr = array [0..100] of String;
   StrXArr = array [0..100] of string;
   Function CutQueryString( ss:PCHAR; var sa:StrArr;len:Integer):Integer;
   Function HexToChar( sword:PCHAR ):char;
   Function DecodeURL( ss :String ):string;

implementation

Function CutQueryString( ss:PCHAR; var sa:StrArr;len:Integer):Integer;
var
   i,index:Integer;
begin
   i:=1;
   index:=0;
   while (i<len) do begin
      while not(ss[i]=#61) do begin  {#61是等号的ASCII}
         i:=i+1;
      end;
      i:=i+1;                        {#38是&符号的ASCII}
      while not(ss[i]=#38) and (i<len) do begin
         sa[index]:=sa[index]+ss[i];
         i:=i+1;
      end;
      index:=index+1;
      if (i<len) then i:=i+1;
   end;
   CutQueryString:=index;
end;

Function HexToChar( sword:PCHAR ):char;
var
   first_char,last_char,result_char:char;
   fo,lo,ro:Integer;
begin
   result_char:=#0;  
   first_char:=sword[0];
   last_char:=sword[1];
   fo:=ord(first_char);
   lo:=ord(last_char);
   if ('0'<=first_char) and (first_char<='9') then
      result_char:=chr(fo-ord('0'))
   else if ('a'<=first_char) and (first_char<='f') then
           result_char:=chr(fo-ord('a')+10)
        else if ('A'<=first_char) and (first_char<='F') then
                result_char:=chr(fo-ord('A')+10);
   result_char:=char(ord(result_char)*16);
   ro:=ord(result_char);
   if ('0'<=last_char) and (last_char<='9') then
      result_char:=chr(ro+lo-ord('0'))
   else if ('a'<=last_char) and (last_char<='f') then
           result_char:=chr(ro+lo-ord('a')+10)
        else if ('A'<=last_char) and (last_char<='F') then
                result_char:=chr(ro+lo-ord('A')+10);
   HexToChar:=result_char;
end;


Function DecodeURL( ss :String ):string;
var url_buf,url_point,rr:PCHAR;
begin
    url_point:=StrAlloc(1000);
    StrPCopy(url_point, ss);
    url_buf:=url_point;
    rr:=url_point;
    while not (url_point^ = chr(0)) do begin
       if (url_point^ = '%') then begin
          url_point:=url_point+1;
          url_buf^:=HexToChar(url_point);
          url_buf:=url_buf+1;
          url_point:=url_point+2;
       end else begin
          if (url_point^ = '+') then url_buf^ := ' '
             else url_buf^ := url_point^;
          url_point := url_point+1;
          url_buf := url_buf+1;
       end;
    end;
    url_buf^:=chr(0);
    DecodeURL:=StrPas(rr);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -