How to get the host from URL in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Uri uri = new Uri("http://seek4info.com/index.php?query=web+hosting");

                Console.WriteLine("Host = {0}", uri.Host);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}


/*
run:

Host = seek4info.com

*/

 



answered Mar 10, 2017 by avibootz

Related questions

1 answer 383 views
1 answer 289 views
2 answers 587 views
587 views asked Mar 31, 2018 by avibootz
2 answers 427 views
2 answers 459 views
1 answer 197 views
197 views asked Jan 31, 2025 by avibootz
1 answer 195 views
...