0

I'm trying to count and print out the numeric value of how many times the "terminator" value has been outputted. Is there any function that does this? If not how should i tackle this problem?

output = get_application_name()
var = string.match("terminator", get_application_name())
print(var)

I would like to count

nil
terminator
nil
nil
terminaor
lama5
  • 11
  • 3
  • Is this homework? It's not against policies, but the premise simply is different, often you are supposed to solve a problem in a certain way - like using loops. Please also check [help/on-topic]. – dualed Feb 26 '18 at 06:25
  • @dualed No, its not a homework. I'm trying to improve window management on my linux box, and for that i need to find out how many instances of the same application are running. I just wanted to find out what would be the best way to go about it, since im not experienced with lua scripting – lama5 Feb 26 '18 at 17:47
  • Then you should absolutely add the window manager in question as a tag, this will attract the crowd you may be looking for – dualed Feb 26 '18 at 18:43

1 Answers1

1

You can make use of the string.gsub function. From the docs:

gsub also returns, as its second value, the total number of matches that occurred.

So:

output = get_application_name()
_, count = output:gsub("terminator", '')
print(output)
hjpotter92
  • 78,589
  • 36
  • 144
  • 183