我正在玩FtpWebRequest,我想知道如何格式化结果?

    FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create("");
        ftp.Credentials = new NetworkCredential("", "");
       ftp.KeepAlive = true;
       ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
       WebResponse response = ftp.GetResponse();
       StreamReader reader = new StreamReader(response
                                       .GetResponseStream());

       string r = reader.ReadLine();
       response.Close();
       reader.Close();

我得到这样的结果
09-17-11  01:00AM               942038 my.zip

什么是将其解析为对象的好方法,比如说
public Class Test()
{
   public DateTime DateCreated? {get; set;}
   public int/long  Size {get; set;}
   public string  Name {get; set;}
}

不知道我是否应该使用long或int作为大小。我也不确定日期时间实际上是创建,修改还是其他日期。

最佳答案

var value = "09-17-11  01:00AM               942038 my.zip";
var tokens = value.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
if (tokens.Length > 3)
{
    var test = new Test
    {
        DateCreated = DateTime.ParseExact(tokens[0] + tokens[1], "MM-dd-yyHH:mmtt", CultureInfo.InvariantCulture),
        Size = int.Parse(tokens[2]),
        Name = tokens[3]
    };

    // at this stage:
    // test.DateCreated = 17/09/2011 01:00AM
    // test.Size = 942038
    // test.Name = "my.zip"
}

关于c# - 如何解析呢? ftpWebRequest ListDirectorDetials,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7476559/

10-13 00:14