日期:2014-05-17 浏览次数:20615 次
List<string> xxx = "abc\r\nef\r\nb\r\nabc".Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();//后面那个参数是把空行过滤掉,如果不过滤就RemoveEmptyEntries改为None
int maxLen = xxx.Max(o => o.Length);
int minLen = xxx.Min(o => o.Length);
List<string> MaxRows = xxx.FindAll(o => o.Length == maxLen);
List<string> MinRows = xxx.FindAll(o => o.Length == minLen);
using (var fs = new FileStream(Server.MapPath("~/test.txt"), FileMode.Open))
{
using (var sr = new StreamReader(fs))
{
var array = sr.ReadToEnd()
.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
.OrderBy(t => t.Length);
var min = array.First();
var max = array.Last();
Response.Write("max: " + max + " </br>");
Response.Write("min: " + min + "</br>");