lua-users home
lua-l archive

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


On Tue, 2011-06-28 at 10:41 -0400, Dave Collins wrote:
> Looks like my split technique doesn’t work on "."
...
> local foo = "foo.bar"
> dump_table(foo:split("."))
> 
> 1=
> 2=
> 3=
> 4=
> 5=
> 6=
> 7=
> 8=
> 
> Sigh. Back to the drawing board...

Don't despair. The dot '.' as a Lua pattern has a special meaning - "any
character". If you do not need to use special patterns as separators,
you can use the fourth (optional) parameter of string.find - 'plain'.
Quoting the manual:

A value of true as a fourth, optional argument plain turns off the
pattern matching facilities, so the function does a plain "find
substring" operation, with no characters in pattern being considered
"magic".

When you change both calls to string.find(self, delimiter, from, true)
then the code behaves as you would like.