String manipulation in Javascript - issue with whitespace -
anybody have advice on following problem? below code. don't know how make program account spaces. thanks!
have function abcheck(str) take str parameter being passed , return string true if characters , b separated 3 places anywhere in string @ least once (ie. "lane borrowed" result in true because there 3 characters between , b). otherwise return string false.
function abcheck(str){ (var = 0; < str.length; i++) { if (str.charat(i) === "a"){ if (str.charat(i+3) === "b") { return true; } } } return false; }
you might have @ regular expressions. here's same function regular expression (it should work, haven't tested yet):
function abcheck(str) { return str.replace(" ","").match(/a([\w\w]{2}b)/g) != null; }
does work you?
also have at: regular expressions - w3c , replace()
Comments
Post a Comment