Suppose I have a string like this
var str = 'E2*2001/116*0364*31'
What I want is to find the 3rd occurrence of * in the string and print up to that from starting.
So result would be E2*2001/116*0364*
I have tried something like this jsfiddle.
Corresponding code
var str = 'E2*2001/116*0364*31',
delimiter = '*',
start = 0,
var pos=getPosition(str, *, 3);
alert(pos);
tokens = str.substring(start, getPosition(str,*,3)),
result = tokens;
document.body.innerHTML = result;
function getPosition(str, m, i) {
return str.split(m, i).join(m).length;
}
But unable to get the output.
Can anyone please assist.