大家说torsion工具中文输入很麻烦,这段时间不忙,刚好静下心来,研究了下,只要把字符串转化从GB2312为UTF-8就可以了。 主要修改static int Sc_ScanString(int ret)这个函数就ok了 static int Sc_ScanString(int ret) { CMDtext[CMDleng - 1] = 0; if(!collapseEscape(CMDtext+1)) return -1; /* CMDlval.str = (char *) consoleAlloc(dStrlen(CMDtext)); dStrcpy(CMDlval.str, CMDtext + 1); */ int n = dStrlen(CMDtext); char tempStr[102400]; dStrcpy(tempStr, CMDtext + 1); convertGB2312toUTF8(tempStr, tempStr, 102400); int count = dStrlen(tempStr); if(n > count) { count = n; count++; CMDlval.str = (char *) consoleAlloc(count); dStrcpy(CMDlval.str, tempStr); } else { count++; CMDlval.str = (char *) consoleAlloc(count); dStrcpy(CMDlval.str, CMDtext + 1); convertGB2312toUTF8(CMDlval.str, CMDlval.str, count); } return(ret); } 不过要自己先写字符转换函数 void convertUTF8toGB2312(const char *unistring, char *outbuffer, int len) { wchar_t *buf = new wchar_t[len]; MultiByteToWideChar(CP_UTF8, 0, unistring, -1, buf, len); WideCharToMultiByte(CP_ACP, 0, buf, -1, outbuffer, len, NULL, NULL); delete []buf; } void convertGB2312toUTF8(const char *unistring, char *outbuffer, int len) { wchar_t *buf = new wchar_t[len ]; MultiByteToWideChar(CP_ACP, 0, unistring, -1, buf, len); WideCharToMultiByte(CP_UTF8, 0, buf, -1, outbuffer, len, NULL, NULL); delete []buf; } WCHAR *UTF8ToUnicode(const char *str) { int i = MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,str,-1,NULL,0); WCHAR *strUnicode=new WCHAR[i]; MultiByteToWideChar(CP_UTF8,MB_ERR_INVALID_CHARS,str,-1,strUnicode,i); return strUnicode; delete []strUnicode; } char *UnicodeToUTF8(const WCHAR* pText) { int i= WideCharToMultiByte(CP_UTF8,0,pText,-1,NULL,0,NULL,NULL); //输入缓冲区大小是宽字符数 char *strUTF8 = new char[i]; WideCharToMultiByte(CP_UTF8,0,pText,-1,strUTF8,i,NULL,NULL); return strUTF8; delete []strUTF8; }