Category talk:Wren-str: Difference between revisions
→Source code: Added Str.occurs method.
(→Source code: Added Str.splitCsv method.) |
(→Source code: Added Str.occurs method.) |
||
Line 343:
var ix = Str.indexOf(ss, search)
return (ix >= 0) ? start + ix : -1
}
// Returns the number of non-overlapping occurrences of the string 't'
// within the string 's'.
static occurs(s, t) { s.split(t).count - 1 }
// Returns the number of non-overlapping occurrences of the string 't'
// within the string 's' starting from codepoint offset 'start'.
static occurs(s, t, start) {
if (start == 0) return occurs(s, t)
return occurs(Str.sub(s, start..-1), t)
}
|