由于% get 被编码为%25您应该能够从字符串中挑选出它们并将它们改回它们的代表字符。
为此,您需要使用 Pos/PosEx 在 str 中找到%并拉出后面的 2 位数字(我认为它总是 2)
这不是我的想法,所以如果它没有编译/参数顺序错误等,请道歉。这应该足以给你一个大致的想法。
function GetNextHex(InStr:String;var Position:Integer):String;
var
NextHex: Integer;
begin
NextHex := PosEx('%', InStr, Position);
if (NextHex > -1) then
Result := Copy(InStr, NextHex, 3)
else
Result := '';
Position := NextHex;
end;
要将十六进制更改为 chr,请将%换成$并使用它,然后您可以根据自己的喜好StrToInt
使用Char
或使用它。Chr
function PercentHexToInt(Hex: String):Integer;
var
str : string;
begin
if (Hex[1] <> '%') then Result := 0
else
begin
// Result := strtoint(StrToHex('$' + Copy(Hex, 1,2)));
str :=StringReplace(HEx,'%','',[rfReplaceAll,rfIgnoreCase]);
str:=trim(str);
Result := StrToInt(('$' +str));
end;
end;
有了这些,您应该能够扫描替换十六进制值的字符串
function ReplaceHexValues(Str: String):String;
var
Position:Integer;
HexValue:String;
IntValue:Integer;
CharValue:String;
begin
Position := 0;
while(Position > -1)
begin
HexValue := GetNextHex(Str, Position);
IntValue := PercentHexToInt(HexValue);
CharValue := Char(IntValue);
if (CharValue = #0) then break;
//Note that Position Currently contains the the start of the hex value in the string
Delete(Str, Position, 3);
Insert(CharValue,Str,Position);
end;
Result:=Str;
end;