Skip to content

Instantly share code, notes, and snippets.

@JamesJJ
Last active October 3, 2018 12:18
Show Gist options
  • Save JamesJJ/0f65fdfeb402287c955c3f50d51bdfd2 to your computer and use it in GitHub Desktop.
Save JamesJJ/0f65fdfeb402287c955c3f50d51bdfd2 to your computer and use it in GitHub Desktop.
using System;
public class Program
{
public static void Main()
{
// example values ...
var uriStringFromDgm = "http://blob-cn.htcvive.com/abc/123qwerty";
var uriStringFromNetMethodTargetField = "https://fast-cdn.wow.com:11443/some_prefix";
// Use UriBuilder
UriBuilder uriDGM = new UriBuilder(uriStringFromDgm);
UriBuilder uriDownload = new UriBuilder(uriStringFromNetMethodTargetField);
// Schema, Host, Port, Path_Prefix from NetMethod
// Only Path_Suffix from DGM
if (uriDownload.Path.Equals("/")) {
uriDownload.Path = uriDGM.Path;
} else {
uriDownload.Path += uriDGM.Path;
}
// The URL to use for download is now ready in "uriDownload"
Console.WriteLine(uriDownload.ToString());
// https://fast-cdn.wow.com:11443/some_prefix/abc/123qwerty
}
}
@kenykhung
Copy link

In case this situation:
var uriStringFromNetMethodTargetField = "https://fast-cdn.wow.com:11443/some_prefix/";
I'll do:
else { uriDownload.Path = $"{uriDownload.Path.TrimEnd('/')}/{uriDGM.Path}"; }

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