javascript - Dividing words from text starting with a certain character -
i want test each word text if starts character # if does, put word in variable 'response' if not, continue searching. tried :
var found = false; (i = 0; < text.length; i++) { if (found = /^#...$/.test(text[i])) { found = true; } if (found== true){ //other stuff } }
could me 1 ?
you can use split on space, , use substring find first letter. compare it.
var arr= text.split(' '); (i = 0; < arr.length; i++) { if (arr[i].substring(0,1) == '#') { console.log('found!: ' + arr[i]); break; } }
Comments
Post a Comment