Skip to content

Instantly share code, notes, and snippets.

@glebov21
Last active September 25, 2024 14:26
Show Gist options
  • Save glebov21/fa5b0ca7cc6694666fdb4c0bd71f8dfa to your computer and use it in GitHub Desktop.
Save glebov21/fa5b0ca7cc6694666fdb4c0bd71f8dfa to your computer and use it in GitHub Desktop.
CombineUrl
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