Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,900 questions

51,831 answers

573 users

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 224 views
224 views asked Feb 1, 2025 by avibootz
1 answer 111 views
111 views asked Feb 1, 2025 by avibootz
1 answer 76 views
76 views asked Feb 1, 2025 by avibootz
1 answer 107 views
107 views asked Feb 1, 2025 by avibootz
1 answer 75 views
1 answer 75 views
1 answer 62 views
62 views asked Jan 31, 2025 by avibootz
...