Created
March 26, 2018 23:18
-
-
Save sachintha81/bfab8e36410f3afbb2b04126781d2263 to your computer and use it in GitHub Desktop.
Intelligent Path.Combine()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Pathy | |
{ | |
public static string Combine(string path1, string path2) | |
{ | |
if (path1 == null) return path2 | |
else if (path2 == null) return path1 | |
else return path1.Trim().TrimEnd(System.IO.Path.DirectorySeparatorChar) | |
+ System.IO.Path.DirectorySeparatorChar | |
+ path2.Trim().TrimStart(System.IO.Path.DirectorySeparatorChar); | |
} | |
public static string Combine(string path1, string path2, string path3) | |
{ | |
return Combine(Combine(path1, path2), path3); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From StackOverflow
https://stackoverflow.com/a/43507984/302248