On 11/11/09 02:06, Sean wrote:
>
> Hi Tony,
>
> The last mile to go:
>
> This always worked: (output is 馬)
> -------------------------------------------
> let input = "\xE9\xA6\xAC"
> let output = iconv(input, "UTF-8", "UTF-8")
> -------------------------------------------
>
> However, this failed: (output is '\xE9\xA6\xAC')
> -------------------------------------------
> let input = "%E9%A6%AC"
> let input = substitute(input, '%', '\\x', 'g')
> let output = iconv(input, "UTF-8", "UTF-8")
> -------------------------------------------
>
> Now, the key becomes how to translate string (single quoted) to string
> (double quoted). I guess that "\x" is meaningful only within double
> quote.
>
> Thanks
>
> Sean
> >
>
what about (untested)
function HttpToString(str)
return substitute(a:str, '%\(\x\x\)',
\ '\=eval(''"\x'' . submatch(1) . ''"'')', 'g')
endfunction
If I haven't goofed,
:echo HttpToStr('%E9%A6%AC')
ought to return
馬
Note the use of pairs of single quotes to represent actual single quotes
in a single-quoted string.
The use of a continuation line assumes 'nocompatible'.
See also
:help sub-replace-expression
:help eval()
Best regards,
Tony.
--
Lizzie Borden took an axe,
And plunged it deep into the VAX;
Don't you envy people who
Do all the things _YOU_ want to do?
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---