String.count: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
mNo edit summary |
||
Line 2: | Line 2: | ||
<lowercasetitle></lowercasetitle> | <lowercasetitle></lowercasetitle> | ||
__NOTOC__ | __NOTOC__ | ||
This function counts how many times a string is found from within another string. | This function counts how many times a string is found from within another string. | ||
Revision as of 23:58, 24 July 2012
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.