lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Thank you for the quick replies.

In fact, I must to convert the string using just lua 5.1 libs due hardware issues. 
But I believe the answers are enough to perform that.

Thank you,
Igor

2015-02-11 17:00 GMT-03:00 Roberto Ierusalimschy <roberto@inf.puc-rio.br>:
> >>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