如何"c:\my\ss\abc.txt"取子串abc.txt?
SubString(一个参数)含义?

解决方案 »

  1.   

    String a = "abc"; 
    a.substring(1) 
    就是"bc",就是从1到end。
    你这个要用到LastIndexof方法
      

  2.   

    txt = @"c:\my\ss\abc.txt";
    int intPlace = txt.LastIndexOf(@"\");
    string str = txt.Substring(intPlace,txt.Length-intPlace);
      

  3.   

    如果是文件的话,使用FileInfo的Name属性。如果非要从字符串去截获,用String.LastIndexOf获得'\\'位置,然后进行SubString。
      

  4.   

    最简单的方法:string fullFileName=@"c:\my\ss\abc.txt";string fileName=fullFileName.Substring(fullFileName.LastIndexOf("\\")+1);楼主可以试下...
      

  5.   

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

  6.   

    string fullFileName = @"c:\my\ss\abc.txt";
    string fileName=System.IO.Path.GetFileName(fullFileName );
      

  7.   

    另一个方法:string ss=@"c:\my\ss\abc.txt";
            ss.TrimStart(@"c:\my\ss\".ToCharArray());