C 分割檔案路徑中的檔名與路徑

2021-08-28 08:22:10 字數 418 閱讀 7166

int lastindex = filepath.lastindexof("\\");  //  \\的意思是,乙個是轉義,乙個是代表斜槓

string pfilepath = filepath.substring(0, lastindex); //檔案路徑

string pfilename = filepath.substring(lastindex + 1); //檔名

string ppath = system.io.path.getdirectoryname(pfullpath); //獲取檔案路徑

string pname = system.io.path.getfilename(pfullpath); //獲取檔名

其中,第二種方法更加思路更加簡單,較為常用。

JS檔名和路徑擷取分割

常用方法有兩種 以 users lz project test.txt為例分別介紹一下 方法一 fullpath users lz project test.txt pos fullpath.lastindexof filename fullpath.substr pos 1 console.log...

C 通過檔案路徑獲取檔名

string fullpath website1 default.aspx 檔名 default.aspx string filename system.io.path.getfilename fullpath 副檔名 aspx string extension system.io.path.get...

C 通過檔案路徑獲取檔名

string fullpath website1 default.aspx string filename system.io.path.getfilename fullpath 檔名 default.aspx string extension system.io.path.getextension...