0
lua, split string
Engaged
,
/t5/lightroom-classic-discussions/lua-split-string/td-p/7886625
Dec 10, 2015
Dec 10, 2015
Copy link to clipboard
Copied
This is almost embarrassing to ask about but I'm stuck. I'm trying to split a string at whitespace. I'm broadly assuming that string.gmatch() returns an array, which it appears to do in the loop example below. However if I try and grab an element from the return value it throws up an error, telling me it's a function. Can anyone help:?
local example = "an example string" -- works as expected. for i in string.gmatch(example, "%S+") do Debug.logn(i) end -- tells me s is a function Debug.logn( string.gmatch( example, "%S+" ) ) -- tells me I'm trying to index a function value Debug.logn( s[1] )
TOPICS
SDK
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/lightroom-classic-discussions/lua-split-string/m-p/7886626#M164651
Dec 10, 2015
Dec 10, 2015
Copy link to clipboard
Copied
string.gmatch() returns an iterator (not an array) that can only be used in a for loop. You may want to use one of the other matching functions:
That comes from the Lua 5.1 Short Reference, which I always keep close at hand.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
kimaldis
AUTHOR
Engaged
,
LATEST
/t5/lightroom-classic-discussions/lua-split-string/m-p/7886627#M164652
Dec 24, 2015
Dec 24, 2015
Copy link to clipboard
Copied
Thanks John.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

