求个正则

zhlin118 2011-09-21 11:43:34
C:\Documents and Settings\Administrator\桌面\ybbm.xls
------------------------------------------------------
把上面最后的文件名取出来 ybbm
...全文
74 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
风之影子 2011-09-21
  • 打赏
  • 举报
回复

FileInfo x =new FileInfo(@"C:\Documents and Settings\Administrator\桌面\ybbm.xls");
string FileName = x.Name;


建议利用.net提供的FileInfor类的Name属性获取
liuyilin888 2011-09-21
  • 打赏
  • 举报
回复

Regex re = new Regex("\\([^\\]*?)\.xls",RegexOptions.None);
MatchCollection matchMade = null;
matchMade = re.Matches("yourStr");
foreach (Match matchMade0 in matchMade)
{
for (int index = 1; index < matchMade0.Groups.Count; index++)
{
MessageBox.Show(matchMade0.Groups[index].Value); //ybbm
}
}
诺维斯基 2011-09-21
  • 打赏
  • 举报
回复
可以不要正则:
string str = "C:\\Documents and Settings\\Administrator\\桌面\\ybbm.xls";
int number1 = str.LastIndexOf("\\");
int number2 = str.LastIndexOf(".");
string newstr = str.Substring(number1+1,number2-number1-1);
Response.Write(newstr);

//ybbm
zhlin118 2011-09-21
  • 打赏
  • 举报
回复

string[] fileStrs = txtFileName.Text.Split(char.Parse(@"\"));
string sheetName = fileStrs[fileStrs.Length - 1].Replace(".xls", "").Replace(".XLS", "");


我的程序处理方法,是不是笨了点? 来个正则啊啊啊!!
liuyilin888 2011-09-21
  • 打赏
  • 举报
回复
学习 学习
hudenq 2011-09-21
  • 打赏
  • 举报
回复
多看点MSDN LIB
zhlin118 2011-09-21
  • 打赏
  • 举报
回复

System.IO.Path.GetFileNameWithoutExtension(txtFileName.Text);

原来自带的有!!结贴了。

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧