How to parse URL in C#

1 Answer

0 votes
using System;

public class parseURL  {
    public static void Main(string[] args) {
        Uri uri = new Uri("https://www.collectivesolver.com:8080/Home/Index.htm?q1=abc&q2=xyz#FragmentName");
        
        Console.WriteLine($"AbsolutePath: {uri.AbsolutePath}");
        Console.WriteLine($"AbsoluteUri: {uri.AbsoluteUri}");
        Console.WriteLine($"DnsSafeHost: {uri.DnsSafeHost}");
        Console.WriteLine($"Fragment: {uri.Fragment}");
        Console.WriteLine($"Host: {uri.Host}");
        Console.WriteLine($"HostNameType: {uri.HostNameType}");
        Console.WriteLine($"IdnHost: {uri.IdnHost}");
        Console.WriteLine($"IsAbsoluteUri: {uri.IsAbsoluteUri}");
        Console.WriteLine($"IsDefaultPort: {uri.IsDefaultPort}");
        Console.WriteLine($"IsFile: {uri.IsFile}");
        Console.WriteLine($"IsLoopback: {uri.IsLoopback}");
        Console.WriteLine($"IsUnc: {uri.IsUnc}");
        Console.WriteLine($"LocalPath: {uri.LocalPath}");
        Console.WriteLine($"OriginalString: {uri.OriginalString}");
        Console.WriteLine($"PathAndQuery: {uri.PathAndQuery}");
        Console.WriteLine($"Port: {uri.Port}");
        Console.WriteLine($"Query: {uri.Query}");
        Console.WriteLine($"Scheme: {uri.Scheme}");
        Console.WriteLine($"Segments: {string.Join(", ", uri.Segments)}");
        Console.WriteLine($"UserEscaped: {uri.UserEscaped}");
        Console.WriteLine($"UserInfo: {uri.UserInfo}");
    }
}



/*
run:

AbsolutePath: /Home/Index.htm
AbsoluteUri: https://www.collectivesolver.com:8080/Home/Index.htm?q1=abc&q2=xyz#FragmentName
DnsSafeHost: www.collectivesolver.com
Fragment: #FragmentName
Host: www.collectivesolver.com
HostNameType: Dns
IdnHost: www.collectivesolver.com
IsAbsoluteUri: True
IsDefaultPort: False
IsFile: False
IsLoopback: False
IsUnc: False
LocalPath: /Home/Index.htm
OriginalString: https://www.collectivesolver.com:8080/Home/Index.htm?q1=abc&q2=xyz#FragmentName
PathAndQuery: /Home/Index.htm?q1=abc&q2=xyz
Port: 8080
Query: ?q1=abc&q2=xyz
Scheme: https
Segments: /, Home/, Index.htm
UserEscaped: False
UserInfo: 

*/

 



answered Jan 31, 2025 by avibootz

Related questions

2 answers 324 views
324 views asked Feb 1, 2025 by avibootz
1 answer 141 views
141 views asked Feb 1, 2025 by avibootz
1 answer 101 views
101 views asked Feb 1, 2025 by avibootz
1 answer 161 views
161 views asked Feb 1, 2025 by avibootz
1 answer 95 views
1 answer 99 views
1 answer 101 views
101 views asked Jan 31, 2025 by avibootz
...