关于截去字符串的问题,谢谢,在线等!

cyhzyh 2007-02-09 10:19:14
文件路径为:C:\我的文档\我的文件夹\cyh.txt
我想截取字符串为:C:\我的文档\我的文件夹\
请问如何实现

注意:文件路径不确定,可以是任何长度的文件路径

谢谢,在线等!
...全文
272 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
jxf654 2007-02-10
  • 打赏
  • 举报
回复
up
Eri 2007-02-09
  • 打赏
  • 举报
回复
楼上的没看题,特别是注意那一行。
wangzhengxing 2007-02-09
  • 打赏
  • 举报
回复
string str1 = @"C:\我的文档\我的文件夹\cyh.txt";

string str2=str1.Substring(0,str1.Length-7);
popeye627 2007-02-09
  • 打赏
  • 举报
回复
樓上那樣好像沒有實現LZ想要的,呵呵,少了最後的\
Snowdust 2007-02-09
  • 打赏
  • 举报
回复
本页页面的顶部BANNER下面有个“管理”,点这个链接。
Red_angelX 2007-02-09
  • 打赏
  • 举报
回复

何必要自己分割呢,最简单的就是最好的
-----------
离开了.Net,你怎么办?
cyhzyh 2007-02-09
  • 打赏
  • 举报
回复
我为什么结不了帖呀
MatrixB 2007-02-09
  • 打赏
  • 举报
回复
何必要自己分割呢,最简单的就是最好的
MatrixB 2007-02-09
  • 打赏
  • 举报
回复
用.net自带的FileInfo类

System.IO.FileInfo fileInfo = new System.IO.FileInfo(@"C:\我的文档\我的文件夹\cyh.txt");
string folder = fileInfo.DirectoryName;
cyhzyh 2007-02-09
  • 打赏
  • 举报
回复
谢谢
Snowdust 2007-02-09
  • 打赏
  • 举报
回复
string fileName = @"C:\我的文档\我的文件夹\cyh.txt";
string path = System.IO.Path.GetDirectoryName(fileName);
MessageBox.Show(path);
Red_angelX 2007-02-09
  • 打赏
  • 举报
回复
string str = @"C:\我的文档\我的文件夹\cyh.txt";
int Index = str.LastIndexOf(@"\");
string NewStr = str.Substring(0, Index+1);
MessageBox.Show(NewStr);
superxiaomm 2007-02-09
  • 打赏
  • 举报
回复
string str = @"C:\我的文档\我的文件夹\cyh.txt";
int Index = str.LastIndexOf(@"\");
string NewStr = str.Substring(0, Index+1);
MessageBox.Show(NewStr);

110,536

社区成员

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

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

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