如何替换URL中的特殊字符? [英] How do I replace special characters in a URL?
问题描述
这可能很简单,但是我根本无法找到答案(
This is probably very simple, but I simply cannot find the answer myself :(
基本的,我想要的是,给出这个字符串:
Basicaly, what I want is, given this string:
http://www.google。 com / search?hl = en&q = c#对象
我想要输出:
http://www.google.com/search?hl = en&q = c%23 +对象
我确定在框架中有一些帮助类,为我照顾,但是我无法找到它。
I'm sure there's some helper class somewhere buried in the Framework that takes care of that for me, but I'm having trouble finding it.
编辑:我应该补充说,这是一个Winforms应用程序。
I should add, that this is for a Winforms App.
推荐答案
HttpServerUtility .UrlEncode(string)
应该整理出任何麻烦的字符
Should sort out any troublesome characters
要使用它,需要t o添加对System.Web(Project Explorer> References> Add reference> System.Web)的引用
To use it you'll need to add a reference to System.Web (Project Explorer > References > Add reference > System.Web)
一旦你这样做,你可以使用它来编码任何项目您希望添加到querystring:
Once you've done that you can use it to encode any items you wish to add to the querystring:
System.Web.HttpUtility.UrlEncode("c# objects");
这篇关于如何替换URL中的特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!