Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lua parse and count a string

Tags:

lua

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.

like image 639
Jack Hammerberg Avatar asked Oct 15 '25 16:10

Jack Hammerberg


1 Answers

You can get just second reply from gsub:

local _, quantity = string.gsub(myString, "%s*\"[^\"]+\"%s*,?", "")
like image 176
Leszek Mazur Avatar answered Oct 18 '25 07:10

Leszek Mazur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!