To create a Uri from a string, you can do this:
Uri u = new Uri("example.com");
But the problem is that the line (for example, above) does not contain the protocol, you will get an exception: " Invalid URI: The format of the URI could not be determined. "
To avoid an exception, you must make sure that the string contains the protocol, for example:
Uri u = new Uri("http://example.com");
But if you take url as input, how can you add a protocol if it is missing? I mean, besides some IndexOf / Substring manipulations?
Something elegant and fast?
Max Favilli Mar 13 2018-11-11T00: 00Z
source share