On 3/7/07, Joseph WU <[EMAIL PROTECTED]> wrote:
Tony's right. I just tested Cyril's solution. Unfortunately, when encoding=utf8 and fileencoding=cp936, line: "let char = matchstr(getline("."), ".", col(".") - 1)" can only get the *FIRST* 8-bit out of a 2-byte cp936-encoded Chinese character. (To my surprise, the hex value of the first 8-bit converted by iconv is correct in cp936 encode standard. I just realized that iconv can just convert a part of one Chinese Character.:) I am trying to see if I can read the whole 2-byte Chinese char out or not.
Try this: let char_int = matchstr(getline("."), ".", col(".") - 1) let char_ext = iconv(char_int, &encoding, &fileencoding) if len(char_ext) == 1 let code_ext = char2nr(char_ext[0]) echo printf("0x%02X", code_ext) else let code_ext = char2nr(char_ext[0]) * 256 + char2nr(char_ext[1]) echo printf("0x%04X", code_ext) endif This should work if `encoding` is utf-8 and `fileencoding` is NOT utf-8 (but any 1-byte or 2-byte encoding should work). This should however NOT work if `encoding` is other than utf-8 or if `fileencodibg` is utf-8 itself. And check for byte order -- I'm not sure whether big-endian or little-endian is correct here. -- Cyril Slobin <[EMAIL PROTECTED]> `When I use a word,' Humpty Dumpty said, <http://45.free.net/~slobin> `it means just what I choose it to mean'