Difference between revisions of "Str.cnt"

From OpenEUO
Jump to: navigation, search
m (Created page with "== 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 o...")
(No difference)

Revision as of 15:53, 11 November 2010

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 string
c0...cN are numbers

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