10

重複の可能性:
C# で URI 文字列からファイル名を取得する

C#でUriからファイル名を抽出するには?

たとえば、私は Uri を持っています

"http://audacity.googlecode.com/files/audacity-win-2.0.exe"

しかし、ファイル名を抽出する方法

"audacity-win-2.0.exe"

文字列として保存しますか?

ありがとうございました、

ジェリー

4

4 に答える 4

7

Path.GetFileName出来る...

        Uri u = new Uri("http://audacity.googlecode.com/files/audacity-win-2.0.exe");
        Path.GetFileName(u.AbsolutePath);
于 2012-06-28T04:56:47.997 に答える
7

どうですか

Path.GetFileName(string path);

あなたの場合

Path.GetFileName(new Uri("http://audacity.googlecode.com/files/audacity-win-2.0.exe").AbsolutePath);
于 2012-06-28T04:55:18.180 に答える
2

例えば

Uri uri = new Uri("http://audacity.googlecode.com/files/audacity-win-2.0.exe");
string Path.GetFileName(uri.AbsolutePath);
于 2012-06-28T04:56:35.287 に答える
0

aが常に物理ファイルを表すと想定するのは安全ではないため、URIaからファイル名を抽出することURIが常に保証されるわけではありません。

于 2012-06-28T04:56:32.060 に答える