C# 字符串截取
C:\Documents and Settings\Administrator\桌面\A0A.xls我怎么取到 A0A.xls
请各位大侠们帮帮忙 ! --------------------编程问答-------------------- 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());
这么简单的问题被你搞的好复杂的说 --------------------编程问答--------------------
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返回最后/的索引下标,再用子字符串函数从该下标截取到末尾。 --------------------编程问答--------------------
--------------------编程问答-------------------- 顶 --------------------编程问答-------------------- 太多了,我不写了!顶一下好了! --------------------编程问答-------------------- Path.GetFileName("") --------------------编程问答-------------------- 学习.. --------------------编程问答-------------------- --------------------编程问答-------------------- 顶,,学习中。。。。 --------------------编程问答-------------------- str.substring(str.length-4) --------------------编程问答-------------------- 随便怎么处理都可以的,
string str = @"C:\Documents and Settings\Administrator\桌面\A0A.xls";
string strName = str.Substring(str.LastIndexOf("\\"));
截取,按字符取,按第二位取,按路径。。。。 --------------------编程问答-------------------- lastindexof('\')不就好了......
补充:.NET技术 , C#