How can I count the occurrences of a specific character into a string, with LUA, please?
I give here an example
let the string: "my|fisrt|string|hello"
I want to count how many occurrences of the character "|" has the string. In this case, it should return 3
How can I do it please?
gsub returns the number of operations in the second value
local s = "my|fisrt|string|hello"
local _, c = s:gsub("|","")
print(c) -- 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With