Finding character position of substring in string

if I have the string aaabbbabbb

I want to enter bbb and return 4 and 8 (the locations of bbb in the string.)

Is there a way to do this?

I just used the javascript plugin in toolbox. the String indexOf(substr,n)

I don’t know what I’m doing. Should this read every position of string “boo” in the larger string? and put them in list n?

var r = [];
var n = [];
var str = “boooboobbbbboo”;
var i = 0;
r[0]=0;

do {
r[i] = (str.indexOf(“boo”,r[i]+1"));
n.push(r[i]);
i++;
} while ((str.indexOf(“boo”,(r[i]+1))) != -1);

Okay. I guess I was bleary eyed last night. This works.

var str = “bbooobboboobbbboo”;

var t;

t=0;

var tback;

var mylist=[];

for(var i=0;i<20;i++) {

t=str.indexOf(“boo”,(tback+1))

if (t==-1) {break};

mylist.push(t);

tback=t;

}

bubble_fn_2(mylist);

This topic was automatically closed after 70 days. New replies are no longer allowed.