将字符串转换为正确的URI格式? [英] Convert string to proper URI format?
本文介绍了将字符串转换为正确的URI格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有简单的方法将电子邮件地址字符串转换为正确的URI格式?
Is there any easy way to convert email address string into proper URI format?
输入:
Input:
http://mywebsite.com/validate_email/3DE4ED727750215D957F8A1E4B117C38E7250C33/myemail@yahoo.com
输出应该是:
Output should be:
http://mywebsite.com/validate_email/3DE4ED727750215D957F8A1E4B117C38E7250C33/myemail%40yahoo.com
如果我没有输出,我会得到一个错误响应,比如
If I didn't do the output, I get an error response like
An Error Was Encountered
The URI you submitted has disallowed characters.
预先感谢!
Thanks in advance !
推荐答案
描述
你必须从url中提取你的QueryString ,编码它们并构建新的url。
Description
You have to extract your QueryString from the url, encode them and build the new url.
string url = "http://mywebsite.com/validate_email/3DE4ED727750215D957F8A1E4B117C38E7250C33/myemail@yahoo.com";
int index = url.LastIndexOf("/");
string queryString = url.Substring(index + 1, url.Length - (index + 1));
url = url.Substring(0, index) + "/" + HttpUtility.UrlEncode(queryString);
// url is now
// http://mywebsite.com/validate_email/3DE4ED727750215D957F8A1E4B117C38E7250C33/myemail%40yahoo.com
更多信息
- String.LastIndexOf方法
- String.Substring方法
- HttpUtility.UrlEncode方法
- String.LastIndexOf Method
- String.Substring Method
- HttpUtility.UrlEncode Method
More Information
这篇关于将字符串转换为正确的URI格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文