开发者

Url escape/unescape functions in MonoTouch

I am looking for url escape and unescape functions in MonoTouch. Essentially I am looking for the MonoTouch equivalent of the method stringByReplacingPercentEscapesUsingEncoding, as in the follow line of objective-c code:

 NSString *args = [(NSString*)[components objectAtIndex:3]
                   stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

I was expecting to be able to translate this to something like this:

string args = URL.Unescape(components[3]);

Do URL escape/unescape functions exist in MonoTouch or do 开发者_开发百科I have to roll my own?


System.Web.HttpUtility.UrlDecode (string s);

Which is in System.Web.Services.dll in monotouch.


It is not present in the version of the .Net framework included with MonoTouch.

I believe I got the source for it off of Google Code here.

You may want to look up the license for this, I used it for a personal iPhone app.


In addition to answer, Split has params parameter Split('&','='); expression firstly split by & then '=' so odd elements are all values to be encoded shown below.

    public static void EncodedQueryString(ref string queryString)
    {
        var array=queryString.Split('&','=');
        for (int i = 0; i < array.Length; i++) {
            string part=array[i];
            if(i%2==1)
            {               
                part=System.Web.HttpUtility.UrlEncode(array[i]);
                queryString=queryString.Replace(array[i],part);
            }
        }
    }

You should encode just the values generally.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜