4

so I have a string that is outputted and it contains little sub strings in it, so it's formated like so "Glyph 1", "Glyph 19", "Glyph 22". What I want to do is to get a number of how many sub strings are in it. Now I know if it was a table that this would pretty easy, just put a '#' in front of it, but this is a string. I've tried using gmatch and split but gmatch seems to divide one string into sub strings and split just makes a table into a string containing sub strings. I'm sure there's some solution I've overlooked.

1
  • 1
    you could use a generic for loop with gmatch and count the matches but if you're not interested in the substrings themselves go with Leszek's solution. there is no split in native Lua Commented Jun 4, 2020 at 6:07

1 Answer 1

2

You can get just second reply from gsub:

local _, quantity = string.gsub(myString, "%s*\"[^\"]+\"%s*,?", "")
Sign up to request clarification or add additional context in comments.

1 Comment

I find your pattern a bit complicated. '%b""' would also do the job. or sub commas and add 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.