在查询字符串中编码空格 [英] Encoding spaces in query strings
问题描述
我正在尝试在查询字符串中将空格编码为%20".我在这里找到了MSDN的som帮助: http://msdn.microsoft.com/en-us/library /zttxte6w.aspx [ ^ ]
当我调用此方法时,它似乎对传入的字符串完全不起作用-即我返回的字符串仍然包含空格.
我想我在这里缺少明显的东西,或者可能完全把错误的树种了.任何帮助将不胜感激.
亲切的祝福,帕特里克
Hi,
I am trying to encode spaces as "%20" in a query string. I found som MSDN help on this here: http://msdn.microsoft.com/en-us/library/zttxte6w.aspx[^]
When I call this method it appears to do absolutely nothing to the string I pass in - i.e. the one I get back still contains spaces.
I think I am missing something obvious here or possibly barking up completely the wrong tree. Any help would be very much appreciated.
Kind wishes, Patrick
推荐答案
尝试时:
litWelcome.Text = "Welcome back " + User.UserName + Server.UrlEncode(" ASP.NET Examples");
我收到消息:
I get the message:
Welcome back OriginalGriff+ASP.NET+Examples
这是我所期望的. UrlEncode不会将空格编码为%20,而是将其替换为"+"
Which is what I would expect. UrlEncode does not encode spaces as %20 - it replaces them with "+"
如链接所示-ASP.NET Examples
将被编码为ASP.NET+Examples
As the link says -ASP.NET Examples
will be encoded toASP.NET+Examples
你好,
感谢您的答复.用"+"编码绝对可以,但是我得到的字符串仍然包含空格.嗯...很奇怪.
-帕特里克
Hi,
Thanks for those replies. Encoding with ''+'' would be absolutely fine but I get back a string that still contains the spaces. Mmm ... very strange.
- Patrick
这篇关于在查询字符串中编码空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!