首页 >> 严选问答 >

如何编写文本(文本文档怎么编程序)

2024-07-01 20:20:01

问题描述:

如何编写文本(文本文档怎么编程序),急到抓头发,求解答!

最佳答案

推荐答案

2024-07-01 20:20:01

ublic class Person : IComparable { public DateTime time; public string name; #region IComparable 成员 public int CompareTo(Person other) { return this.time.CompareTo(other.time); } #endregion } class Program { static void Main(string[] args) { string s = @"0时0分14秒 玩家10时0分29秒 玩家20时0分1秒 玩家30时0分34秒 玩家40时0分4秒 玩家50时0分5秒 玩家60时0分49秒 玩家70时0分30秒 玩家8"; List lst = new List(); Regex r = new Regex("(?[\S]+)[\s]+(?[\S]+)"); Match m = r.Match(s); while (m.Success) { Person p = new Person(); p.time = DateTime.Parse(m.Groups["t"].Value); p.name = m.Groups["u"].Value; lst.Add(p); m = m.NextMatch(); } //排序操作。

只有泛型集合中的对象实现了IComparable接口才能进行排序。

lst.Sort(); foreach (Person item in lst) { Console.WriteLine(***.name + ":" + string.Format("{0:HH时MM分ss秒}", item.time)); } Console.WriteLine("Finish!!!"); Console.ReadKey(); }如果你是初学者,估计你看这段代码是会有困难的。

  免责声明:本答案或内容为用户上传,不代表本网观点。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。 如遇侵权请及时联系本站删除。

 
分享:
最新文章