9

C# – 直接取得不包含副檔名的檔案名稱

 3 years ago
source link: https://naclyen.com/2008/09/23/c-%e7%9b%b4%e6%8e%a5%e5%8f%96%e5%be%97%e4%b8%8d%e5%8c%85%e5%90%ab%e5%89%af%e6%aa%94%e5%90%8d%e7%9a%84%e6%aa%94%e6%a1%88%e5%90%8d%e7%a8%b1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
C# – 直接取得不包含副檔名的檔案名稱 – NaCl's Blog

承上面那篇…
不曉得會啥 input 底下應該要裝著 AssetName 的變數會是個 null…
山不轉路轉,路不轉我轉!

既然得不到資源名稱,想想,資源名稱的預設值通常都是從檔名來的…
那就從檔名下手吧!


假設SourceFilename內容為 C:\\~TEMP\\HeightmapCollision\\HeightmapCollision\\Content\\tutorial 4.bmp
我們需要從中取得檔案名稱,但不包括副檔名,也就是 tutorial 4.

String assetName = Path.GetFileNameWithoutExtension(input.Identity.SourceFilename);

就這樣簡單!
assetName 的內容就是我們要的結果tutorial 4.

標籤: C#

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK