I have the following code snippet:
string tmp = String.Format(\"
A more generic solution (works with http, https, ftp...) based on Ian Flynn idea. This method does not remove custom port, if any. Custom port is defined automatically depending on the protocol.
var uriBuilder = new UriBuilder("http://www.google.fr/");
if (uriBuilder.Uri.IsDefaultPort)
{
uriBuilder.Port = -1;
}
return uriBuilder.Uri.AbsoluteUri;