C # sorting list by substring

I have a list of lines:

\\\\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\\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 must be a new line. sorry for the poor formatting

I need to sort the list by file name 15939-E.ESY etc. I need a complete list in alphabetical order by file name. how would i sort it this way?

+4
source share
1 answer

I would use Path.GetFileName like this

 list = list.OrderBy(s=>Path.GetFileName(s)).ToList(); 

Where list is a collection of these lines.

+6
source

Source: https://habr.com/ru/post/1332825/


All Articles