当前位置:编程学习 > C#/ASP.NET >>

C# 字符串截取

C:\Documents and Settings\Administrator\桌面\A0A.xls


我怎么取到 A0A.xls


请各位大侠们帮帮忙 ! --------------------编程问答-------------------- Path.GetFileName("") --------------------编程问答--------------------
引用 1 楼 wuyq11 的回复:
Path.GetFileName("")


学习..

string str = @"C:\Documents and Settings\Administrator\桌面\A0A.xls";
Console.WriteLine(Path.GetFileName(@"C:\Documents and Settings\Administrator\桌面\A0A.xls"));   //A0A.xls
Console.WriteLine((str.Substring(str.LastIndexOf(@"\"), str.Length - str.LastIndexOf(@"\"))).Replace(@"\", ""));   //A0A.xls
--------------------编程问答--------------------

public static  string SubDisk(string str) { 
            string a="C:\\Documents and Settings\\Administrator\\桌面\\";
            return str.Substring(0,str.Length);
        }
--------------------编程问答--------------------
            string str =@"C:\Documents and Settings\Administrator\桌面\A0A.xls";
            string [] array = str.Split(new char[] { '\\'});
            Console.WriteLine(array[array.Length - 1].ToString());
--------------------编程问答--------------------
引用 2 楼 happycell188 的回复:
引用 1 楼 wuyq11 的回复:
Path.GetFileName("")


学习..

C# code
string str = @"C:\Documents and Settings\Administrator\桌面\A0A.xls";
Console.WriteLine(Path.GetFileName(@"C:\Documents and Settings\Admin……



这么简单的问题被你搞的好复杂的说 --------------------编程问答--------------------
string result = System.IO.Path.GetFileName(@"C:\Documents and Settings\Administrator\桌面\A0A.xls
")
--------------------编程问答--------------------

public static  string SubDisk(string str) { 
            string a="C:\\Documents and Settings\\Administrator\\桌面\\";
            return str.Substring(a.Length, str.Replace(a,"").Length);
        }

写错啦 --------------------编程问答-------------------- Path.GetFileName("") --------------------编程问答-------------------- 用lastindexof返回最后/的索引下标,再用子字符串函数从该下标截取到末尾。 --------------------编程问答--------------------

string str = @"C:\Documents and Settings\Administrator\桌面\A0A.xls";
string strName = str.Substring(str.LastIndexOf("\\"));
 
--------------------编程问答--------------------
引用 9 楼 jinyuttt 的回复:
用lastindexof返回最后/的索引下标,再用子字符串函数从该下标截取到末尾。
顶 --------------------编程问答-------------------- 太多了,我不写了!顶一下好了! --------------------编程问答-------------------- Path.GetFileName("") --------------------编程问答-------------------- 学习.. --------------------编程问答-------------------- --------------------编程问答-------------------- 顶,,学习中。。。。 --------------------编程问答-------------------- str.substring(str.length-4) --------------------编程问答-------------------- 随便怎么处理都可以的,
截取,按字符取,按第二位取,按路径。。。。 --------------------编程问答-------------------- lastindexof('\')不就好了......
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,