lua-users home
lua-l archive

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


On Wed, Sep 15, 2021 at 2:53 PM Flyer31 Test <flyer31@googlemail.com> wrote:
>
> But what is really a bit not so nice in lua, if you are used to C at
> least, is that you can not easily check the first character of a
> string... e. g. if you use a string for setting some function options,
> it would be quite nice if you could check the start character beeing
> 'a' or other char without invoking a string lib function

You can: 'a' <= str and str < 'b'.

Caveat from the manual: "if both arguments are strings, then their
values are compared _according to the current locale_" - emphasis
added.

Another thing to observe is that if you need access to individual
bytes of a string, string.byte() may be a superior choice over
string.sub() because, at least in theory, the former does not need to
allocate garbage-collected memory unlike the latter.

If your strings are UTF-8 encoded, then utf8.codepoint() might be
similarly considered.

Cheers,
V.