Skip to content

Instantly share code, notes, and snippets.

@sachintha81
Created March 26, 2018 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sachintha81/bfab8e36410f3afbb2b04126781d2263 to your computer and use it in GitHub Desktop.
Save sachintha81/bfab8e36410f3afbb2b04126781d2263 to your computer and use it in GitHub Desktop.
Intelligent Path.Combine()
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);
}
}
@sachintha81
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment