在乌里更换主机 [英] Replace host in Uri

查看:142
本文介绍了在乌里更换主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是更换乌里使用.NET的主机部分的最好方法是什么?

What is the nicest way of replacing the host-part of an Uri using .NET?

即:

string ReplaceHost(string original, string newHostName);
//...
string s = ReplaceHost("http://oldhostname/index.html", "newhostname");
Assert.AreEqual("http://newhostname/index.html", s);
//...
string s = ReplaceHost("http://user:pass@oldhostname/index.html", "newhostname");
Assert.AreEqual("http://user:pass@newhostname/index.html", s);
//...
string s = ReplaceHost("ftp://user:pass@oldhostname", "newhostname");
Assert.AreEqual("ftp://user:pass@newhostname", s);
//etc.

的System.Uri似乎并没有多大帮助。

System.Uri does not seem to help much.

推荐答案

System.UriBuilder 是你以后有什么...

System.UriBuilder is what you are after...

这篇关于在乌里更换主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆