String.count: Difference between revisions
Jump to navigation
Jump to search
m (dont mix languages) |
No edit summary |
||
Line 1: | Line 1: | ||
{{Useful Function}} | |||
<lowercasetitle></lowercasetitle> | |||
__NOTOC__ | |||
This function counts how many times a string is found from within another string. | |||
==Syntax== | |||
<syntaxhighlight lang="lua">int string.count(string text, string search)</syntaxhighlight> | |||
===Required Arguments=== | |||
*'''text:''' A string to find the text from | |||
*'''search:''' A string defining what to find | |||
== Code == | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function string.count(text, search) | function string.count(text, search) |
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.