c# 分割字符串问题

来源:百度知道 编辑:UC知道 时间:2024/05/24 20:49:17
如何能将文件绝对路径中的文件名,不包括扩展名提取出来呢?
如:将e:\eiene\ieieie\happy.rar中的happy提取出来

string ss = "e:\\eiene\\ieieie\\happy.rar";
string mm = ss.Substring(ss.LastIndexOf("\\") + 1, ss.LastIndexOf(".") - ss.LastIndexOf("\\") - 1);

string str = @"e:\eiene\ieieie\happy.rar";
int s = str.LastIndexOf(@"\");
int e = str.LastIndexOf(@".");
文件名=str.Substring(s + 1, e - s);

string fileName = System.IO.Path.GetFileNameWithoutExtension(@"e:\eiene\ieieie\happy.rar");

string str =你的路径;
int s1 = str.LastIndexOf(@"\");
int s2 = str.LastIndexOf(@".");
str name=str.Substring(s1 + 1, s2 - s1);

using System.IO;
string strPath = @"C:\Documents and Settings\DELL\桌面";

Path.GetDirectoryName(strPath);
Path.GetExtension(strPath);
Path.GetFileName(strPath);

openFileDialog1.SafeFileName读取文件名(包括扩展名)