62,041
社区成员
发帖
与我相关
我的任务
分享
string[] str = new string[] { "str_user_201203130509.txt", "str_user_201203120608.txt", "str_user_201203270809.txt", "str_user_201203140905.txt" };
int cur = 0;
int max = 0;
foreach (string s in str)
{
cur = (int)(s.Replace("str_user_", "").Replace(".txt", ""));
if (cur > max)
{
max = cur;
}
}
string maxString = "str_user_" + max.ToString() + ".txt";
static void Main(string[] args)
{
string[] str = new string[] { "str_user_201203130509.txt", "str_user_201203120608.txt", "str_user_201203270809.txt", "str_user_201203140905.txt" };
List<string> list = new List<string>();
for (int i = 0; i < str.Length; i++)
{
list.Add(str[i].Substring(9, 12));
}
list.Sort();
list.Reverse();
Console.WriteLine("str_user_" + list[0] + ".txt");
Console.ReadLine();
}
static void Main(string[] args)
{
string[] str = new string[] { "str_user_201203130509.txt", "str_user_201203120608.txt", "str_user_201203270809.txt", "str_user_201203140905.txt" };
var q = str.OrderByDescending(p => Convert.ToInt64(p.Substring(9,12))).First();
Console.WriteLine(q);
Console.ReadLine();
}
string[] arr = new string[] { "str_user_201203120608.txt", "str_user_201203130509.txt", "str_user_201203140905.txt", "str_user_201203270809.txt" };
Array.Sort(arr);
string lastOne = arr[arr.Length - 1];
MessageBox.Show(lastOne);