c# sorting list by substring
i have a list of strings:
\\\\Tecan1\\tecan #1 output\\15939-E.ESY\r\n
\\\\Tecan1\\tecan #1 output\\15942-E.ESY\r\n
\\\\Tecan1\\tecan #1 output\\15945-E.ESY\r\n
\\\\Tecan1\\tecan #1 output\\15948-E.ESY\r\n
\\\\Tecan1\\tecan #1 output\\15951-E.ESY\r\n
\\\\Tecan1\\tecan #1 output\\15954-E.ESY\r\n
\\\\Tecan1\\tecan #1 output\\15957-E.ESY\r\n
\\\\Tecan1\\tecan #1 output\\15960-E.ESY\r\n
\\\\Tecan1\\tecan #1 output\\15963-E.ESY\r\n
\\\\Tecan_2\\output on tecan 2\\15940-E.ESY\r\n
\\\\Tecan_2\\output on tecan 2开发者_StackOverflow社区\\15943-E.ESY\r\n
\\\\Tecan_2\\output on tecan 2\\15946-E.ESY\r\n
\\\\Tecan_2\\output on tecan 2\\15949-E.ESY\r\n
\\\\Tecan_2\\output on tecan 2\\15952-E.ESY\r\n
\\\\Tecan_2\\output on tecan 2\\15955-E.ESY\r\n
\\\\Tecan_2\\output on tecan 2\\15958-E.ESY\r\n
\\\\Tecan_2\\output on tecan 2\\15961-E.ESY\r\n
\\\\Tecan-5\\Output\\15941-E.ESY\r\n
\\\\Tecan-5\\Output\\15944-E.ESY\r\n
\\\\Tecan-5\\Output\\15947-E.ESY\r\n
\\\\Tecan-5\\Output\\15950-E.ESY\r\n
\\\\Tecan-5\\Output\\15953-E.ESY\r\n
\\\\Tecan-5\\Output\\15956-E.ESY\r\n
\\\\Tecan-5\\Output\\15959-E.ESY\r\n
\\\\Tecan-5\\Output\\15962-E.ESY\r\n
each \r\n should be a new line. sorry for the bad formatting
i need to sort the list of by the file name 15939-E.ESY
, etc... i need the entire list in alphanumerical order by the filename. how would i sort it this way?
I'd use Path.GetFileName
like this
list = list.OrderBy(s=>Path.GetFileName(s)).ToList();
Where list
is a collection of those lines.
精彩评论