Showing posts with label port numbers. Show all posts
Showing posts with label port numbers. Show all posts

Thursday, 19 June 2008

How do I remove the port number from a URL in C#.NET?

Regular Expression:
:{1}\d*

Using C#.NET, the above regular expression can be applied to a URL to strip the port number (along with ":"):

Regex regex = new Regex( @":{1}\d{1,}" );
string url = regex.Replace( "http://andrewgunn.blogspot.com:81/", string.Empty );