デコードする必要があります:
file://localhost/G:/test/%E6%B0%97%E3%81%BE%E3%81%90%E3%82%8C%E3%83%AD%E3%83%9E%E3%83%B3%E3%83%86%E3%82%A3%E3%83%83%E3%82%AF.mp3
の中へ
file://localhost/G:/test/気まぐれロマンティック.mp3
2009年以前のDelphiでそれを行う方法(私はDelphi 2006を使用しています)?
私は Delphi 2006 を持っていないので、Delphi 2007 でコードをテストしました。あなたがすべき:
「%」文字を含む文字列をプレーンな UTF8 文字列に変換します。
UTF8 文字列をワイド文字列 (UTF8Decode) に変換します。
ワイド文字列を日本語エンコードの Ansi 文字列に変換します (WideCharToMultiByte):
const
SrcStr = 'file://localhost/G:/test/%E6%B0%97%E3%81%BE%E3%81%90%E3%82%8C%E3%83%AD%E3%83%9E%E3%83%B3%E3%83%86%E3%82%A3%E3%83%83%E3%82%AF.mp3';
function Src2Utf8(const S: string): string;
var
I: Integer;
S1: string;
B: Byte;
begin
I:= 0;
Result:= '';
SetLength(S1, 3);
S1[1]:= '$';
while I < Length(S) do begin
Inc(I);
if S[I] <> Char('%') then Result:= Result + S[I]
else begin
Inc(I);
S1[2]:= S[I];
Inc(I);
S1[3]:= S[I];
B:= StrToInt(S1);
Result:= Result + Char(B);
end;
end;
end;
procedure TForm8.Button1Click(Sender: TObject);
var
S: WideString;
S1: string;
begin
S:= Utf8Decode(Src2Utf8(SrcStr));
SetLength(S1, 4 * Length(S)); // more than enough
FillChar(PChar(S1)^, Length(S1), 0);
WideCharToMultiByte(932 {shift-jis codepage}, 0, PWideChar(S), Length(S),
PChar(S1), Length(S1), nil, nil);
S1:= PChar(S1); // to remove ending zeroes
Label1.Caption:= S1;
end;
上記のコードをさまざまなフォントでテストしたところ、「@」で始まる名前のフォントの日本語記号は、質問の日本語文字列と比較して反時計回りに 90 度回転しているように見えました。SHIFTJIS_CHARSET を使用した "Arial Unicode MS" フォントは、正確な (回転していない) 外観を提供します。
IdURI ユニットの Indy TIdURI クラスには、UrlDecode / UrlEncode 関数が含まれています。エンコーディング パラメータを持つ Indy の最近のバージョン (10.5.8) で試すことができます。
class function TIdURI.URLDecode(ASrc: string; AByteEncoding: TIdTextEncoding = nil
{$IFDEF STRING_IS_ANSI}; ADestEncoding: TIdTextEncoding = nil{$ENDIF}
): string;
私は解決策を見つけました。ここにポインタがあります: delphigroups.info/2/5/209620.html次に、httpApp.pas で HttpDecode を試してください。解決策は次のとおりです。
TntEdit2.Text := UTF8Decode(HTTPDecode('file://localhost/G:/test/%E6%B0%97%E3%81%BE%E3%81%90%E3%82%8C%E3%83%AD%E3%83%9E%E3%83%B3%E3%83%86%E3%82%A3%E3%83%83%E3%82%AF.mp3'));
mjnは正しいかもしれませんが、Delphi内であらゆる種類のUnicodeを処理する場合は、上司にDelphiの最新バージョン(またはDelphi 2009)にアップグレードするように説得することを強くお勧めします。Delphi 2009でのUnicodeサポートは非常に優れており、そのまま使用できます。これが本当にできない場合は、TNTコンポーネントが機能しましたが、Borlandから箱から出してすぐに使用する方がはるかに簡単だったため、最終的にはDelphi2009がリリースされるのを待ちました。