1

I get a code from google to say for example. The bellow example contains non-ascii chars in a string. What i want is to write a function that can convert them all into ASCII string.

{e:"vLuDULDKEomjiAfgo4CwBg",c:0,u:"https://www.google.com/complete/search?client\x3dserp\x26hl\x3den\x26sugexp\x3dles%3B\x26gs_nf\x3d3\x26pq\x3dC%23%20decode%20hex%20string%20to%20string\x26cp\x3d11\x26gs_id\x3d3w8\x26xhr\x3dt\x26q\x3dhow%20to%20conv\x26tch\x3d1\x26ech\x3d78\x26psi\x3dDrqDUKC_I86fiAfLrYCgCw.1350810126009.3",d:"[\x22how to conv\x22,[[\x22how to conv\\u003Cb\\u003Eert pdf to word\\u003C\\/b\\u003E\x22,0,[]],[\x22how to conv\\u003Cb\\u003Eert flv to mp3\\u003C\\/b\\u003E\x22,0,[]],[\x22how to conv\\u003Cb\\u003Eert prc to pdf\\u003C\\/b\\u003E\x22,0,[]],[\x22how to conv\\u003Cb\\u003Eert jpg to pdf\\u003C\\/b\\u003E\x22,0,[]],[\x22how to conv\\u003Cb\\u003Eert pdf to epub\\u003C\\/b\\u003E\x22,0,[]],[\x22how to conv\\u003Cb\\u003Eert cr2 to jpeg\\u003C\\/b\\u003E\x22,0,[]],[\x22how to conv\\u003Cb\\u003Eert pdf to excel\\u003C\\/b\\u003E\x22,0,[]],[\x22how to conv\\u003Cb\\u003Eert amr to mp3\\u003C\\/b\\u003E\x22,0,[]],[\x22how to conv\\u003Cb\\u003Eert prc to epub\\u003C\\/b\\u003E\x22,0,[]],[\x22how to conv\\u003Cb\\u003Eert flv to avi\\u003C\\/b\\u003E\x22,0,[]]],{\x22j\x22:\x223w8\x22,\x22q\x22:\x22HhWOfQJyxGUsSNB1855GU4lNjzU\x22}]"}/*""*/

Here is the function i have but it doesn't work out with the string above:

        public static string DecodeHex(string data)
    {
        data = data.Replace("\x22", @"""");
        data = data.Replace("\x23", "#");
        data = data.Replace("\x24", "$");
        data = data.Replace("\x25", "%");
        data = data.Replace("\x26", "&");
        data = data.Replace("\x27", "'");
        data = data.Replace("\x28", "(");
        data = data.Replace("\x29", ")");
        data = data.Replace("\x2a", "*");
        data = data.Replace("\x2b", "+");
        data = data.Replace("\x2c", ",");
        data = data.Replace("\x2d", "-");
        data = data.Replace("\x2e", ".");
        data = data.Replace("\x2f", "/");
        data = data.Replace("\x30", "0");
        data = data.Replace("\x31", "1");
        data = data.Replace("\x32", "2");
        data = data.Replace("\x33", "3");
        data = data.Replace("\x34", "4");
        data = data.Replace("\x35", "5");
        data = data.Replace("\x36", "6");
        data = data.Replace("\x37", "7");
        data = data.Replace("\x38", "8");
        data = data.Replace("\x39", "9");
        data = data.Replace("\x3a", ":");
        data = data.Replace("\x3b", ";");
        data = data.Replace("\x3c", "<");
        data = data.Replace("\x3d", "=");
        data = data.Replace("\x3e", ">");
        data = data.Replace("\x3f", "?");
        return data;
    }

thanks for reply.

0

3 Answers 3

5
string url = "https://www.google.com/complete/search?client\x3dserp\x26hl\x3den\x26sugexp\x3dles%3B\x26gs_nf\x3d3\x26pq\x3dC%23%20decode%20hex%20string%20to%20string\x26cp\x3d11\x26gs_id\x3d3w8\x26xhr\x3dt\x26q\x3dhow%20to%20conv\x26tch\x3d1\x26ech\x3d78\x26psi\x3dDrqDUKC_I86fiAfLrYCgCw.1350810126009.3";
Uri uri = new Uri(url);
Console.WriteLine(uri.ToString());
3

you can also use the following method

HttpUtility.UrlDecode(String) from System.Web
1
0
    var json1 = DecodeHex(json);
    var jsonDes = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(json1);
    public static string DecodeHex(string data)
    {
        data = data.Replace("\\x22", @"""");
        data = data.Replace("\\x23", "#");
    .......
    }

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.