c# - Replace host in Uri -


What is the best way to change the host part of the URI?

Ie:

  Replace string (string origin, string newHostName); // ... string s = ReplaceHost ("http: //oldhostname/index.html", "newhostname"); Assure. Erequal ("http: //newhostname/index.html", s); // ... string s = ReplaceHost ("http: // user: pass@oldhostname/index.html", "newhostname"); Assign. Arequal ("http: // user: pass@newhostname/index.html", s); // ... string s = ReplaceHost ("ftp: // user: pass @ oldhostname", "newhostname"); Assign. Erequal ("ftp: // user: pass @ newhostname", s); //e.t.c.  

System. Yuri does not seem to help so much

what are you after ...

  string reposthost ( String origin, string newHostName) {var builder = new UriBuilder (original); Builder.Host = newHostName; Return Builder. URI ToString (); }  

Comments