String.count: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
No edit summary |
||
Line 29: | Line 29: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
outputChatBox(string.count("A Text", "T")) -- and the result is 2! | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Code and Edit by Krischkros. | Code and Edit by Krischkros. |
Revision as of 23:28, 2 March 2016
This function counts how many times a string is found from within another string.
Syntax
int string.count(string text, string search)
Required Arguments
- text: A string to find the text from
- search: A string defining what to find
Code
function string.count(text, search) if search and text then local string_count = 0 for i in string.gfind(text, search) do string_count = string_count + 1 end return string_count else return 0 end end
Usage:
outputChatBox(string.count("A Text", "T")) -- and the result is 2!
Code and Edit by Krischkros.