Last active
September 25, 2024 14:26
-
-
Save glebov21/fa5b0ca7cc6694666fdb4c0bd71f8dfa to your computer and use it in GitHub Desktop.
CombineUrl
This file contains hidden or 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 string CombineUrl(params string[] uriParts) | |
{ | |
string uri = string.Empty; | |
if (uriParts != null && uriParts.Length > 0) | |
{ | |
char[] trims = new char[] { '\\', '/' }; | |
uri = (uriParts[0] ?? string.Empty).Trim(trims); | |
for (int i = 1; i < uriParts.Length; i++) | |
{ | |
var rightPart = (uriParts[i] ?? string.Empty).Trim(trims); | |
if (uri == null || uri.Length == 0) | |
uri = rightPart; | |
else | |
uri = string.Format("{0}/{1}", uri, rightPart); | |
} | |
} | |
return uri.Replace('\\', '/'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment