最佳答案
要从一个字符串创建一个 Uri,你可以这样做:
Uri u = new Uri("example.com");
但问题是,如果字符串(像上面的那个)不包含协议,你会得到一个异常: “ 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");
但是如果您将 URL 作为输入,那么如果缺少该协议,如何添加该协议呢?
I mean apart from some IndexOf/Substring manipulation?
优雅又快捷的东西?