/* * Author: Leng_que * Date: 2009-10-20 10:30:00 * E-mail: leng_que@yahoo.com.cn * Description: Decode some string of encode by Unicode. */ #include <windows.h> #include <stdio.h> #include <math.h> //Hexadecimal convert to decimal. int str_HexToDec(char* hex) { int tmp=0; int result=0; int len = strlen(hex); for ( int n=(len-1); n>=0; n-- ) { tmp = hex[n]; if ( tmp>=48 && tmp<=57 ) { result += (tmp-48)*(int)pow(16, len-n-1); } else { tmp = tolower(tmp); if ( tmp>='a' && tmp<='f' ) { result += (tmp-87)*(int)pow(16, len-n-1); } else { return -1; } } } return result; } //Decode the [in] of encode by Unicode and separated by [separator]. void decodeUnicode(char* in, char* separator) { char* token=NULL; char dest[3]={0}; WCHAR num=0; token = strtok(in, separator); while ( token ) { num = str_HexToDec(token); memset(dest, 0, sizeof(dest)); WideCharToMultiByte( CP_ACP, 0, &num, -1, dest, 2, NULL, NULL ); //Output the result. printf("%s", dest); token = strtok(NULL, separator); } } //The main function. int main(void) { char in[]="%u8c22%u8c22%u4f60%uff0c%u6742%u8349%u6e05%u9664%u5e72%u51c0%u4e86%uff01"; char separator[]="%u"; decodeUnicode(in, separator); return 0; } 下面是程序的输出结果(呵呵,估计已经有朋友知道我在探究什么了): 谢谢你,杂草清除干净了!