javascript - How to get the positions of an specified char? -


i have string "hello world". want positions of char "l" string.

my code following:

str = "hello world"; pos = str.search(/l/g); out.value = pos; 

the result of code 2, wanted result 2,3,9.

how can result?

edit: help.

but want sum of (2+1*105) + (3+1*105) + (9+1*105).

can me again?

what small function it?

str = "hello world"; find = (function(str,c){     results = []       for(i=0;i<str.length;i++){        if (str[i].tolowercase()===c)            results.push(i)     }     return results }); find(str,'l') 

here working fiddle: http://jsfiddle.net/bx8sj0gv/


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -