Delphi7 中文汉字转网址格式 Utf8编码转换(淘宝搜索中文转网址)

function HttpEncode(S:AnsiString):string;

var

  P:^Byte;

  I:Cardinal;

begin

  Result:='';

  P:=@S[1];

  Result:=Format('%%%x',[Ord(P^)]);

  for I := 1 to Length(S)-1 do

  begin

    Inc(P);

    Result:=Format('%s%%%x',[Result,Ord(P^)]);

  end;

end;

function HttpDecode(str:AnsiString): string;

var

  List: TStrings;

  tmpStr: AnsiString;

  i: Integer;

begin

  List := TStringList.Create;

  ExtractStrings(['%'], ['%'], PChar(str), List);

  SetLength(tmpStr, List.Count);

  for i := 0 to List.Count - 1 do

  Byte(tmpStr[i+1]) := StrToInt('$' + List[i]);

  List.Free;

  Result := Utf8Decode(tmpStr);

end;

procedure TuMain.btnStartClick(Sender: TObject);

    var

    i :integer;

   s: string;

begin

  s:='衣服';

  s:=HttpEncode(AnsiToUtf8(s));

  showmessage(s);                                            //显示 %E8%A1%A3%E6%9C%8D

  s := HttpDecode(s);

  showmessage(s);

end;

上一篇:ThreeJS的特效合成器和后期处理通道


下一篇:ThreeJS文字作为纹理贴图