delphi中怎么将"鞋子"两字转化成"%D0%AC%D7%D3"样式呢?在其它程序里一般情况是UrlEncode或是类似的内容,delphi有何类似函数?

解决方案 »

  1.   

    showmessage(format('%s,%s,%s,%s', [inttohex(ord('鞋子'[1]),1),
          inttohex(ord('鞋子'[2]),1), inttohex(ord('鞋子'[3]),1),
            inttohex(ord('鞋子'[4]),1)]))
      

  2.   

    showmessage(format('%s', [inttohex(ord('鞋子'[1]),1)])+'%'+
                format('%s', [inttohex(ord('鞋子'[2]),1)])+'%'+
                format('%s', [inttohex(ord('鞋子'[3]),1)])+'%'+
                format('%s', [inttohex(ord('鞋子'[4]),1)])+'%')补充一下 其实和1 楼完全是一样的
      

  3.   

    showmessage(
               '%'+format('%s', [inttohex(ord('鞋子'[1]),1)])+
               '%'+format('%s', [inttohex(ord('鞋子'[2]),1)])+
               '%'+format('%s', [inttohex(ord('鞋子'[3]),1)])+
               '%'+format('%s', [inttohex(ord('鞋子'[4]),1)]))
      

  4.   

    “鞋子”結果為:BE%63%A4%6C% 和搜索引擎得出來的結果不一樣:%D0%AC%D7%D3
      

  5.   

    Format中两个%代表一个%
      ShowMessage(Format('%%%.2x%%%.2x%%%.2x%%%.2x', [Ord('鞋子'[1]), Ord('鞋子'[2]), Ord('鞋子'[3]), Ord('鞋子'[4])]));//参考如下代码
    function UrlEncode(mUrl: string): string;
    var
      I: Integer;
    begin
      Result := '';
      for I := 1 to Length(mUrl) do
      begin
        case mUrl[I] of
          #33..#126: Result := Result + mUrl[I];
        else Result := Result + '%' + IntToHex(Ord(mUrl[I]), 2);
        end;
      end;
    end; { UrlEncode }procedure TForm1.Button1Click(Sender: TObject);
    begin
      Caption := UrlEncode('鞋子')
    end;