2011-11-14 5 views
1

私は次の文字列だ:「D:\ソリューション\ TestPlugin \プラグイン\ DashboardSimuを」と私が抽出したい:「DashboardSimu」パスの最後のフィールドを取得していますか?

はそれを得るための簡単な方法はありますか?

任意の助けを事前に

おかげで...私はこれが初心者の質問です知っているが、私はforループせずにそれを行うには管理しないと、私は驚き、他の方法がないだろう。

答えて

2

あなたは1つが、私が望んでいたまさにであることを続い

DirectoryInfo di = new DirectoryInfo("Your path"); 

その後、

String lastField = di.Name; 
+0

として行うことができます! –

4

おそらくSystem.IO.Path.GetFileName()探している:

using System.IO; 

string lastComponent 
    = Path.GetFileName(@"D:\Solutions\TestPlugin\Plugins\DashboardSimu"); 
// Now lastComponent is "DashBoardSimu". 
1
string path = @"D:\Solutions\TestPlugin\Plugins\DashboardSimu"; 
string file = Path.GetFileName(path); 

と同様:

string dir = @"D:\Solutions\TestPlugin\Plugins", file = "DashboardSimu"; 
string path = Path.Combine(dir, file); 
2

あなたは、次のいずれかの方法でこれを行うことができるはず

string folderName = new DirectoryInfo(@ "D:\Solutions\TestPlugin\Plugins\DashboardSimu").name; 

または

関連する問題