Str.cnt

From OpenEUO
Revision as of 18:08, 24 November 2010 by Ximan (Talk | contribs) (Calling Pattern)

Jump to: navigation, search

Calling Pattern

Call

local r[,c...] = sl.str.cnt(s1,s2[,bsimple[,bpos]])

Args

s1 is a string
s2 is a string
bsimple (optional) is a boolean or nil
bpos (optional) is of any type

Results

r is a number, the count of occurrences of s2 in s1
c0...cN are numbers, the locations where s1 was found

Usage Example

local s = sl.str
local i = 'This is a test'
local j = 'is'
local r,c1,c2 = s.cnt(i,j,true,true)
print(r..' '..c1..' '..c2)
--> 2 3 6

Description

Counts the number of occurrences of string s2 in string s1 and optionally returns the positions as well. If argument bsimple is left unspecified, or is specified as true, then pattern matching is disabled and a plain search is undertaken. If bsimple is specified as false, then pattern matching will be performed. If bpos is specified as true, then the positions of the substring in string s1 will also be returned following the occurrence count.

Upon Error

Cnt fails silently. If s1 or s2 aren't strings, then 0 (zero) is returned.

See Also