lua-users home
lua-l archive

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


Il 07/11/2015 19:25, Dirk Laurie ha scritto:
2015-11-07 20:05 GMT+02:00 Marco Atzori <marco.atzori.1983@gmail.com>:
Il 07/11/2015 18:54, Dirk Laurie ha scritto:
local s = tokens( "apple.banana.cherry.grape.orange",".")
Because 46 is the ASCII code of the dot. If I want, for example, tokenize
the string with another character (which can be a letter, number, comma,
semicolon, hash or any ASCII character from 1 to 255) with your code this is
not possible because it is limited to only dot as a separator between
tokens.

local text = "Roses-are-red-violets-are-blue"

As you can see, your code is unable to get "violets", when you just need
enter 45 instead of 46.
I paid your question the compliment of actually implementing and
testing my answer. It is a disappointment that you have summarily
dismissed that answer without bothering to read it carefullly.

    s = tokens("Roses-are-red-violets-are-blue","-")

s:gettok(4)
violets

Really sorry for my "bad" answer, I was in a hurry and did not read carefully your answer. Thanks for the tips, and I still ask pardon for first

Marco