WoW:USERAPI CountChars: Difference between revisions

m
Move page script moved page USERAPI CountChars to WoW:USERAPI CountChars without leaving a redirect
mNo edit summary
m (Move page script moved page USERAPI CountChars to WoW:USERAPI CountChars without leaving a redirect)
 
(2 intermediate revisions by 2 users not shown)
Line 8: 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 return the length of ''haystack'')
:;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.


''Note: Arguments are cast into strings before any processing is done.''<br />
''Known Issue(1): Regular expressions sometimes won't find all instances of needle in haystack.''
=== Returns ===
=== Returns ===


Line 27: Line 29:
  number2 = 2
  number2 = 2
  number3 = 3
  number3 = 3
  number4 = 2 -- even though there's actually 3 ("rld", "rcr", and "raf"). ''Known Issue(1)''
  number4 = 3


==Code==
==Code==
Line 37: 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 49: Line 54:


__NOTOC__
__NOTOC__
[[Category:User Defined Functions]]
[[Category:User defined functions]]
Anonymous user