String.count: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
This Function counts a text from a text.
This Function counts a text from a text.
It is server side and client side!


<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 13: Line 14:
end
end
end
end
</syntaxhighlight>
Usage:
<syntaxhighlight lang="lua">
outputChatbox(string.count("A Text", "T")) -- and the result is 2!
</syntaxhighlight>
</syntaxhighlight>

Revision as of 11:00, 30 June 2012

This Function counts a text from a text. It is server side and client side!

function string.count(text, search)
	if searchand 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!