在Delphi7中更改字符

在Delphi7中更改字符,delphi,delphi-7,Delphi,Delphi 7,我正在开发一个从互联网下载和修改文本文件的程序。 这是该文件的一行: 55,-63-K%C3%BAsky+m%C5%88a,533,557,754625,10160,0 我想将此行修改为: 55,-63-Kúsky mňa,533,557,754625,10160,0 这意味着我想将像%C3%BA这样的文本片段修改为字母u,atc 我写了这个单元: unit Moj_PHP_Text; interface uses SysUtils; const MAX_CH = 37;

我正在开发一个从互联网下载和修改文本文件的程序。 这是该文件的一行:

55,-63-K%C3%BAsky+m%C5%88a,533,557,754625,10160,0
我想将此行修改为:

55,-63-Kúsky mňa,533,557,754625,10160,0
这意味着我想将像
%C3%BA
这样的文本片段修改为字母
u
,atc

我写了这个单元:

unit Moj_PHP_Text;

interface

uses SysUtils;

const
   MAX_CH = 37;
   tab1:array[1..MAX_CH] of string=('%C3%A1','%C3%81','%C3%A4','%C4%8D','%C4%8C',
                                    '%C4%8E','%C3%A9','%C4%9B','%C3%AD','%C3%8D',
                                    '%C4%BE','%C5%99','%C5%88','%C5%A1','%C5%A5',
                                    '%C3%BA','%C3%9A','%C3%BD','%C5%AF','%C5%BE',
                                    '%C5%BD','%C5%98','%C5%A0','%C3%B4','%C5%A4',
                                    '%C4%8F','%C3%9D','%C3%89','%C3%B3','%C3%A0',
                                    '%C5%9A','%C4%BD','%C3%BC','%C5%87','%C5%8D',
                                    '%C3%96','%C3%B6');
  tab2:array[1..MAX_CH] of char=('á','Á','ä','è','È',
                                 'Ï','é','ì','í','Í',
                                 '¾','ø','ò','š','',
                                 'ú','Ú','ý','ù','ž',
                                 'Ž','Ø','Š','ô','',
                                 'ï','Ý','É','ó','a',
                                 'Œ','¼','ü','Ò','o',
                                 'Ö','ö');

function DecodePHPText(st1: string): string;

implementation

function DecodePHPText(st1: string): string;
var i,j:integer;
    st,stt:string;
    ch:char;
    jj,male:boolean;
    znak:byte;
begin
st:=''; stt:=''; jj:=true; male:=false; j:=0; 
for i:=1 to length(st1) do begin
    if jj then begin
       ch:=st1[i];
       if ch='+' then ch:=' ';
       if (ch='%') then begin
          stt:=copy(st1,i,3);
          if not(stt='%C3') and not(stt='%C4') and not(stt='%C5') then begin
             stt:=copy(stt,2,2);
             stt:='$'+stt;
             znak:=strtoint(stt);
             ch:=chr(znak);
             male:=true;
             jj:=false;
             end else begin
                 stt:=copy(st1,i,6);
                 for j:=1 to MAX_CH do
                     if tab1[j]=stt then begin
                     ch:=tab2[j];
                     jj:=false;
                     male:=false;
                     end;
             end;
      end;
   j:=i;
   st:=st+ch;
   end;
if ((i=j+2) and male) or ((i=j+5) and not male) then begin
   jj:=true;
   j:=0;
   end;
end;
result:=st;
end;

end.
是否有任何例程可以将D7中的文本
%C3%A1
转换为字符
a
? 或者我必须继续填充数组Tab1和Tab2?

好的,问题解决了。 我找到了我需要的东西。这是一个功能。我修改了这个函数,现在它工作得很好。感谢kbec的来信,我必须寻找的是…;-)

以下是该函数:

function DecodePHPText(const Data:string):string;
var t:AnsiString;
    p,q,l:integer;
    b:byte;
begin
  l:=Length(Data);
  SetLength(t,l);
  q:=1;
  p:=1;
  while (p<=l) do begin
    case char(Data[p]) of
      '+':t[q]:=' ';
      '%': begin
             inc(p);
             b:=0;
             case char(Data[p]) of
               '0'..'9':inc(b,byte(Data[p]) and $F);
               'A'..'F','a'..'f':inc(b,(byte(Data[p]) and $F)+9);
             end;
             inc(p);
             b:=b shl 4;
             case char(Data[p]) of
               '0'..'9':inc(b,byte(Data[p]) and $F);
               'A'..'F','a'..'f':inc(b,(byte(Data[p]) and $F)+9);
             end;
             t[q]:=AnsiChar(b);
           end else t[q]:=Data[p];
    end;
    inc(p);
    inc(q);
  end;
  SetLength(t,q-1);
  Result:=UTF8Decode(t);
  if (q>1) and (Result='') then Result:=t;
end;
函数DecodePHPText(常量数据:字符串):字符串;
var t:翻译;
p、 q,l:整数;
b:字节;
开始
l:=长度(数据);
设定长度(t,l);
q:=1;
p:=1;
而(p1)和(Result='')则Result:=t;
结束;

查找类似于
uridecode