一種在 C# 中獲取檔名的方法
將路徑名設為字串 -
string myPath = "D:\
ew\quiz.txt";
現在,使用 GetFileName() 方法獲取檔案的檔名 -
Path.GetFileName(myPath)
以下是完成的程式碼 -
示例
using System;
using System.IO;
namespace Demo {
class Program {
static void Main(string[] args) {
string myPath = "D:\
ew\quiz.txt";
// get extension
Console.WriteLine("Extension: "+Path.GetExtension(myPath));
// get path
Console.WriteLine("File Path: "+Path.GetFileName(myPath));
}
}
}輸出
Extension: .txt File Path: D:
ew\quiz.txt
廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP