C#语言如何将字符串类型转换成Uri类型

如题所述

需要使用的类:System.Web.HttpUtility

UrlEncode() 方法用来编码

UrlDecode() 方法用来解码示例:

//对 URL ç¼–码进行解码
string s = "%5B1%2C2%5D";
string result = System.Web.HttpUtility.UrlDecode(s);

//对 å­—符串进行 URL ç¼–码
string s = "[1,2]";
string result = System.Web.HttpUtility.UrlEncode(s);
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-05-14
Uri myUri = new Uri("http://www.contoso.com/");

第2个回答  推荐于2018-03-09
直接使用Uri类的构造函数或者使用TypeDescriptor+TypeConverter 类自己转换本回答被网友采纳
相似回答