如何传递一个包含&的字符串在它内部作为wp8中的参数 [英] How Do I Pass A String That Has & Inside It as a parameter in wp8

查看:42
本文介绍了如何传递一个包含&的字符串在它内部作为wp8中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//这是我传递的字符串

  string  myItem =   Love& Drugs; 



 NavigationServices.Navigate( new  Uri( string  .Format(< span class =code-string>  / Views / Page.xaml?item = {0},myItem))); 





//这是我在OnNavigatedTo方法中检索它的方式



 MyTextBox.Text = NavigationContext.QueryString [  item]; 





//输出是





我的问题是为什么不是从& Drugs开始或检索的字符串的其余部分,或者我做错了什么?

解决方案

D.国内危险化学品。请问HttpUtility.UrlEncode有帮助吗?

http://msdn.microsoft.com /en-us/library/4fkewx0t(v=vs.110).aspx [ ^ ]


你需要对URL进行编码。 [ ^ $



使用System.Net添加; 位于代码文件的顶部。

使用 WebUtility.UrlEncode方法 [ ^ ]编码URL:

  string  encodedItem = WebUtility.UrlEncode(myItem); 
NavigationServices.Navigate( new Uri( string .Format( / Views / Page.xaml?item = {0},encodedItem)));


//Here is the string i am passing

string myItem = "Love & Drugs";


NavigationServices.Navigate(new Uri(string.Format("/Views/Page.xaml?item={0}",myItem)));



//this is how i retrieve it in OnNavigatedTo method

MyTextBox.Text = NavigationContext.QueryString["item"];



//output is

Love



My question is why isn't the rest of the string starting from "& Drugs" being passed or retrieved or i'm i doing something wrong??

解决方案

Dunno. Will HttpUtility.UrlEncode help?
http://msdn.microsoft.com/en-us/library/4fkewx0t(v=vs.110).aspx[^]


You need to encode the URL.[^]

Add using System.Net; at the top of your code file.
Use the the WebUtility.UrlEncode method[^] to encode the URL:

string encodedItem = WebUtility.UrlEncode(myItem);
NavigationServices.Navigate(new Uri(string.Format("/Views/Page.xaml?item={0}",encodedItem)));


这篇关于如何传递一个包含&amp;的字符串在它内部作为wp8中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆