Parsing a URL – C# and Java

Parsing a URL – C# and Java

C# - Parsing a URL 範例:


{
        class Program
        {
                public static void Main(string[] args)
                {                       
                        // TODO: Implement Functionality Here
                        string url = "http://www.yahoo.com:80/en/index.html?name=joe#first";
                        System.Uri uri = new System.Uri(url);
                        
                        Console.WriteLine("protocol:"+uri.Scheme);
                        Console.WriteLine("port:" + uri.Port);
                        Console.WriteLine("host:" + uri.Host);
                        Console.WriteLine("path:"  +  uri.GetComponents(UriComponents.Path, UriFormat.UriEscaped));
                        Console.WriteLine("file:"  +  uri.GetComponents(UriComponents.PathAndQuery, UriFormat.UriEscaped));
                        Console.WriteLine("query:" +  uri.GetComponents(UriComponents.Query, UriFormat.UriEscaped));
                        Console.WriteLine("ref:"   +  uri.GetComponents(UriComponents.Fragment, UriFormat.UriEscaped));
                        Console.Write("Press any key to continue . . . ");
                        Console.ReadKey(true);
                }
        }
}



Java - Parsing a URL 範例
java_demo