[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Convert utf8 string to iso8859-1 (Latin1)
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 11 Feb 2015 18:00:13 -0200
> >>Is there a way to covert a string whose characters are encoded in utf8, to
> >>a string with characters encoded in iso-8859-1, just using lua standard
> >>libs? I cannot use libs with C codes.
> >>
> [...]
>
> Actually, the Latin 1 subset of unicode has the same codepoints as
> Latin1. It's just that UTF-8 is a different encoding. The following
> suffices to do the conversion with Lua 5.3:
>
> [...]
In Lua 5.3, that would do it:
string.gsub(s, utf8.charpattern, function (c)
return string.char(utf8.codepoint(c))
end)
-- Roberto