You are not logged in.
Pages: 1
/// string_find_all(str, substr)
// Returns an array containing the position of all instances of substr in str.
var s, ss, slen, sslen;
var ar, n;
s = argument[0];
ss = argument[0];
slen = string_length(s);
sslen = string_length(ss);
n = 0;
for (var = i = 1, j = 1; i <= slen; i++)
{
if (string_char_at(ss, j) == string_char_at(s, i))
{ j++; }
if (j == sslen)
{
ar[n] = (i - sslen)+1;
n++;
j = 0;
}
}
return ar;
Last edited by nmejames (2018-01-25 03:08:51)
Offline
This is a good idea for a script — sort of surprised it's not part of the collection already. Still considering whether or not "tootoot" should find "toot" once or twice. Obviously your way is the faster option. A simple regex query would only find it once so I guess this is good.
Thanks for the submission.
Abusing forum power since 1986.
Offline
As example:
<?php
$str = 'tootoot';
var_dump(substr_count($str, 'toot'));
returns 1, so it's another vote for keeping it this way. But it would be good to have string_find_all_overlapped or something too.
Offline
Pages: 1