开发者

decoding hexdecimals from URLs

a lot of sites like google and wikipedia encode non-english characters in hex with a leading '%' sign. I looked for a tool that I could pipe URLs into it and, when such %AA strings are met, will transla开发者_StackOverflowte these signs back to utf so that I can read them.

as I couldn't find one, I wrote it myself in c and I'd like to share it with you, maybe you'll find it useful:

#include <stdio.h>
int main()
   {
        char c;
        unsigned int i;
        while (!feof(stdin))
        {
                if (0==fread(&c,1,1,stdin)) break;
                if (c!='%') putchar(c);
                else
                {
                        if (scanf("%X",&i)==1) putchar(i);
                        else putchar('%');
                }
        }
        return 0;
}

usage example:

# echo "http://he.wikipedia.org/wiki/%D7%A2%D7%9E%D7%95%D7%93_%D7%A8%D7%90%D7%A9%D7%99" | ./dumpHex

results:

http://he.wikipedia.org/wiki/עמוד_ראשי


In VC++:

string dec = URLDecoder::decode(url)

PHP:

$d = urldecode($u)

Java:

String dec = URLDecoder.decode(url,"UTF-8");

etc...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜