从ftp服务器上得到某一个文件夹下的一个文件名,文件名以字符串形式返回,
比如f="03-03-09  03:59PM                 1995 FB090303.16h",其中03-03-09  03:59PM是时间,1995是大小,FB090303.16h是文件名,怎么从字符串中得到FB090303.16h?
原来用f.Split(" ".ToCharArray()),如果文件名中有空格就错了。

解决方案 »

  1.   

    class Program
    {
        static void Main(string[] args)
        {            
            string param2 = @"[^\S]+";
            string str = "03-03-09  03:59PM                1995 FB090303.16h";            
            string[] str2 = Regex.Split(str, param2);
            foreach (string s in str2)
            {
                Console.WriteLine(s);
            }
        }
    }
    /*
    03-03-09
    03:59PM
    1995
    FB090303.16h
    请按任意键继续. . .
    */
      

  2.   

    using System.Text.RegularExpressions;class Program
    {
        static void Main(string[] args)
        {            
            string param2 = @"[^\S]+";
            string str = "03-03-09  03:59PM                1995 FB090303.16h";
            string[] str2 = Regex.Split(str, param2);            
            string outString = str2[str2.Length-1];
            Console.WriteLine(outString);
        }
    }
    /*
    FB090303.16h
    请按任意键继续. . .
    */
      

  3.   

     MatchCollection mac = Regex.Matches(str, @"\s{1}\w*\.{1}\w*");
                foreach (Match m in mac)
                {
                    Console.WriteLine(m.Value);
                }
      

  4.   

    文件名中有空格,比如f="03-03-09  03:59PM                1995 FB09 0303.16h"
    可以吗?
      

  5.   

    try...string test = "03-03-09  03:59PM                1995 FB09 0303.16h";
    string fileName = System.Text.RegularExpressions.Regex.Match(test, @"(?<=^\s*\d{2}-\d{2}-\d{2}\s*\d{2}:\d{2}\s*\S*\s+\d+\s+).*$").Value;
    richTextBox2.Text = fileName;
      

  6.   

    @"(?<=^\s*\d{2}-\d{2}-\d{2}\s*\d{2}:\d{2}\s*\S*\s+\d+\s+).*$"顶,很好理解哦。。