如何"c:\my\ss\abc.txt"取子串abc.txt?

xiamin 2006-10-29 10:33:45
如何"c:\my\ss\abc.txt"取子串abc.txt?
SubString(一个参数)含义?
...全文
143 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sanniko 2006-10-29
  • 打赏
  • 举报
回复
另一个方法:

string ss=@"c:\my\ss\abc.txt";
ss.TrimStart(@"c:\my\ss\".ToCharArray());
rijcm 2006-10-29
  • 打赏
  • 举报
回复
string fullFileName = @"c:\my\ss\abc.txt";
string fileName=System.IO.Path.GetFileName(fullFileName );
liujia_0421 2006-10-29
  • 打赏
  • 举报
回复
测试如下:

string fullFileName = @"c:\my\ss\abc.txt";
string fileName = fullFileName.Substring(fullFileName.LastIndexOf("\\") + 1);
Console.WriteLine(fileName );
Console.ReadLine();

输出:
abc.txt
liujia_0421 2006-10-29
  • 打赏
  • 举报
回复
最简单的方法:

string fullFileName=@"c:\my\ss\abc.txt";

string fileName=fullFileName.Substring(fullFileName.LastIndexOf("\\")+1);

楼主可以试下...
Knight94 2006-10-29
  • 打赏
  • 举报
回复
如果是文件的话,使用FileInfo的Name属性。

如果非要从字符串去截获,用String.LastIndexOf获得'\\'位置,然后进行SubString。
peeperp 2006-10-29
  • 打赏
  • 举报
回复
txt = @"c:\my\ss\abc.txt";
int intPlace = txt.LastIndexOf(@"\");
string str = txt.Substring(intPlace,txt.Length-intPlace);
vfan2010 2006-10-29
  • 打赏
  • 举报
回复
String a = "abc";
a.substring(1)
就是"bc",就是从1到end。
你这个要用到LastIndexof方法

110,561

社区成员

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

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

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