m
Move page script moved page USERAPI CountChars to WoW:USERAPI CountChars without leaving a redirect
m (New page: {{userfunc}} <!-- Leave this line in! --> <center>'''CountChars''' ''- by egingell -''</center> Return how many times ''needle'' is contained in ''haystack''. number = ...) |
m (Move page script moved page USERAPI CountChars to WoW:USERAPI CountChars without leaving a redirect) |
||
| (3 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
{{userfunc}} <!-- Leave this line in! --> | {{userfunc}} <!-- Leave this line in! --> | ||
Return how many times ''needle'' is contained in ''haystack''. | Return how many times ''needle'' is contained in ''haystack''. | ||
| Line 9: | Line 8: | ||
:;haystack: String - The search subject. | :;haystack: String - The search subject. | ||
:;needle: The string to look for. ''needle'' can be a regular expression ('[a-z%s%d]' will | :;needle: The string to look for. ''needle'' can be a regular expression ('[a-z%s%d]' will count all alphanumeric characters and white spaces) | ||
;Notes | |||
: Arguments are cast into strings before any processing is done. | |||
: The search is not case-sensitive. | |||
=== Returns === | === Returns === | ||
| Line 28: | Line 29: | ||
number2 = 2 | number2 = 2 | ||
number3 = 3 | number3 = 3 | ||
number4 = | number4 = 3 | ||
==Code== | ==Code== | ||
| Line 38: | Line 39: | ||
local s, e = strfind(haystack, needle, pos) | local s, e = strfind(haystack, needle, pos) | ||
if e then | if e then | ||
pos = e + 1 | pos = e | ||
if s == e then | |||
pos = pos + 1 | |||
end | |||
end | end | ||
if s and e then | if s and e then | ||
| Line 50: | Line 54: | ||
__NOTOC__ | __NOTOC__ | ||
[[Category:User | [[Category:User defined functions]] | ||