English 中文(简体)
我怎么能有同样的编码说明?
原标题:How can I have same encoded string?

I encoded “ Central Time (US & Canada)” with C#.

timeZone =Server.UrlEncode ("Central Time (US & Canada)");

我想有同样的条码。

Ruby UrlEncode==> Central%252BTime%252B%2528US%252B%252526%252BCanada%2529
.Net UrlEncode twice=> Central%252bTime%252b%28US%252b%252526%252bCanada%29
.Net UrlEncode==> Central%2BTime%2B%28US%2B%2526%2BCanada%29

我如何追捕同样的编码拼凑?

感谢。

最佳回答

我解决这个问题。

类似:

 public string Encode(string text)
    {

        byte[] myASCIIBytes = UnicodeEncoding.Unicode.GetBytes(text);

        byte[] myUTF8Bytes = Encoding.Convert( Encoding.Unicode,UTF8Encoding.UTF8, myASCIIBytes);

        return Encoding.Default.GetString(myUTF8Bytes);
    }

protected string UrlEncodePost(string value)
    {
        StringBuilder result = new StringBuilder();

        foreach (char symbol in value)
        {
            if (unreservedChars.IndexOf(symbol) != -1)
            {
                result.Append(symbol);
            }
            else
            {
                result.Append( %  + String.Format("{0:X2}", (int)symbol));
            }
        }

        return result.ToString();
    }



   timeZone = UrlEncodePost(Encode("Central Time (US & Canada)"));

And I updated ComputeHash function in the OAuthBase.cs file. =>

 private string ComputeHash(HashAlgorithm hashAlgorithm, string data) {
        if (hashAlgorithm == null) {
            throw new ArgumentNullException("hashAlgorithm");
        }

        if (string.IsNullOrEmpty(data)) {
            throw new ArgumentNullException("data");
        }

        byte[] myBytes = UnicodeEncoding.Unicode.GetBytes(data);

        byte[] myUTF8Bytes = Encoding.Convert(Encoding.Unicode, UTF8Encoding.UTF8, myBytes);

        byte[] hashBytes = hashAlgorithm.ComputeHash(myUTF8Bytes);

        return Convert.ToBase64String(hashBytes);

    }
问题回答

否则,如果你愿意,可将其置于方括号内。 你们只得 ask。 在这种情形下,该办法明确规定了所有“非言词”性质(经常表示不公)必须编码:

 URI.encode("Central Time (US & Canada)", /W/)
 # => "Central%20Time%20%28US%20%26%20Canada%29"

我不肯定为什么如此。 网上编码为<代码>+,然后是《国际仲裁裁决汇编》编码,似乎细分如下:

 URI.decode( Central%2BTime%2B%28US%2B%2526%2BCanada%29 )
 # => "Central+Time+(US+%26+Canada)"

EDIT (删除先前错误的答复)

希望能做的是罚款。

        string s = "Central Time (US & Canada)";


        s = System.Web.HttpUtility.UrlEncode(s,System.Text.Encoding.ASCII);
        s = System.Web.HttpUtility.UrlEncode(s, System.Text.Encoding.ASCII);
        s = s.Replace("-","%2D");
        s = s.Replace("_","%5F");
        s = s.Replace("!","%21");
        s = s.Replace("*","%2A");
        s = s.Replace("(","%28");
        s = s.Replace(")","%29");
        s = System.Web.HttpUtility.UrlEncode(s, System.Text.Encoding.ASCII);

        if (s.ToLower() == "Central%252BTime%252B%2528US%252B%252526%252BCanada%2529".ToLower())
        {
            System.Diagnostics.Debug.WriteLine("Success");
        }




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签