DBF表导入UTF-8格式文本时的乱码问题
现在win10保存txt文本文件时是默认用UTF-8格式,当DBF表导入UTF-8格式的txt文本时,中文字符都成了乱码。SDF这个参数好像只适用于ANSI格式的文本。把文本另存为ANSI格式是可以解决乱码问题,但麻烦了点。请教各位老师和前辈,有没有更好的办法。我用的是VFP6。谢谢!
DECLARE long WideCharToMultiByte IN kernel32 long,long,string,long,string@,long,string@,long DECLARE long MultiByteToWideChar IN kernel32 long,long,string,long,string@,long #define CP_UTF8 65001 #define ERROR_NO_UNICODE_TRANSLATION 1113 cUtf8 = AnsiToUtf8("中国") ? Utf8ToAnsi(cUtf8) RETURN FUNCTION AnsiToUtf8(cAnsi) LOCAL WChar, WCharSize, cUtf8 WChar = STRCONV(cAnsi+CHR(0),5) WCharSize = WideCharToMultiByte(CP_UTF8, 0, WChar, -1, NULL, 0, NULL, 0) IF WCharSize==0 OR WCharSize==ERROR_NO_UNICODE_TRANSLATION RETURN "" ENDIF cUtf8 = SPACE(WCharSize) IF WideCharToMultiByte(CP_UTF8,0,WChar,-1,@cUtf8,WCharSize,NULL,0) != WCharSize RETURN "" ENDIF RETURN cUtf8 ENDFUNC FUNCTION Utf8ToAnsi(cUtf8) LOCAL WCharSize, buf WCharSize = MultiByteToWideChar(CP_UTF8, 0, cUtf8, -1, NULL, 0) IF WCharSize==0 OR WCharSize==ERROR_NO_UNICODE_TRANSLATION RETURN "" ENDIF buf = SPACE(WCharSize*2) && 要足够大 IF MultiByteToWideChar(CP_UTF8,0,cUtf8,-1,@buf,WCharSize) != WCharSize RETURN "" ENDIF buf = STRCONV(buf,6) RETURN LEFT(buf,AT(CHR(0),buf)-1) ENDFUNC