how to extract common file path from list of file paths in c#

后端 未结 9 1459
粉色の甜心
粉色の甜心 2021-01-17 15:42

What is the best way extract the common file path from the list of file path strings in c#?

Eg: I have a list 5 file paths in List variable, like below

c:\

9条回答
  •  滥情空心
    2021-01-17 16:18

    I don't think there's a "trick"to get past using the brute force method to do this comparison, but you can optimize your solution somewhat:

    Prepare:
    Find the shortest string
    
    Repeat:
    See if all of the other strings contain it
    If so, you're done
    If not, remove one or more characters
    

提交回复
热议问题