//函数: function ToUTF8Encode(str: string): string; var b: Byte; begin for b in BytesOf(UTF8Encode(str)) do Result := Format('%s%%%.2x', [Result, b]); end;
//测试: var str: string; begin str := '万一'; str := ToUTF8Encode(str); ShowMessage(str); //%E4%B8%87%E4%B8%80 end; --------------------------------------------------------------------------------
function ToUTF8Decode(const str: string): 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;