Saturday, 15 January 2011

Javascript Search for String Starting at End & Stopping at Another String -



Javascript Search for String Starting at End & Stopping at Another String -

i have string this:

the planet big , planet heavy.

using javascript, search string starting end , stopping @ string.

an illustration be, start @ word heavy, search word planet, stop @ word big. sec instance of planet in illustration want, not first. hence if there not instance of planet between big , heavy want yield indexof -1.

thanks.

edit: can accomplish splitting string on word want searching sec element of array text wondering if there function this.

you split on word "big" , lastindexof lastly subsstring group.

ie:

function foo(input,search,stopword){ //split input var arr=input.split(stopword); //return lastly substring grouping homecoming arr[arr.length-1].lastindexof(search); } foo("the planet big , planet heavy.","planet","big");

does give result expect?

javascript

No comments:

Post a Comment