Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4065964
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:04:45+00:00 2026-05-20T16:04:45+00:00

To create a Uri from a string you can do this: Uri u =

  • 0

To create a Uri from a string you can do this:

Uri u = new Uri("example.com");

But the problem is if the string (like the one above) doesn’t contain the protocol you will get an exception: “Invalid URI: The format of the URI could not be determined.“

To avoid the exception you should secure the string includes a protocol, like below:

Uri u = new Uri("http://example.com");

But if you take the url as input, how can you add the protocol if it’s missing?

I mean apart from some IndexOf/Substring manipulation?

Something elegant and fast?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T16:04:45+00:00Added an answer on May 20, 2026 at 4:04 pm

    You could also use UriBuilder:

    public static Uri GetUri(this string s)
    {
        return new UriBuilder(s).Uri;
    }
    

    Remarks from MSDN:

    This constructor initializes a new instance of the UriBuilder class with the Fragment, Host, Path, Port, Query, Scheme, and Uri properties set as specified in uri.

    If uri does not specify a scheme, the scheme defaults to "http:".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To create a new event handler on a control you can do this c.Click
I create a new Button object but did not specify the command option upon
I create a GUID (as a string) and get the hash of it. Can
I create new ASP.NET web application that use SMTP to send message. The problem
This seems like it should be simple, but maybe I'm missing something. I just
I create a TextArea in actionscript: var textArea:TextArea = new TextArea(); I want it
I'm trying to interface with the Google Reader (undocumented/unofficial) API using information from this
I noticed the function Object.factory(char[] className) in D. But it does not work like
Hi i am trying to read the content into string from feed items. SyndicationFeed
create table person ( name varchar(15), attr1 varchar(15), attr2 varchar(1), attr3 char(1), attr4 int

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.