desithugg Posted August 15, 2008 Share Posted August 15, 2008 Hi, I'm trying to convert a function someone wrote for me in PHP a while back which returns the text between two objects in an array. For example. text="[saad]hello[/saad]sffsad90aa89a8da[saad]bye[/saad]"; found=findText("[saad]","[/saad]",text); //found[0] would return hello //found[1] would return bye Below is what I've wrote, but it doesn't seem to be working. I believe the problem is the !==, anybody else have a clue? function mySubStr(strP,startP,endP){ if(endP==0) endP=strP.length-startP; return strP.substr(startP,endP); } function myIndexOf(strP,searchP){ return strP.indexOf(searchP); } function findText(openPin,endPin,hayStack){ var textFound = new Array(); openPin = openPin.toLowerCase(); endPin = endPin.toLowerCase(); var opLength = opLength.length; var epLength = epLength.length; var hsCheck = hsCheck.toLowerCase(); do{ opPos=myIndexOf(hsCheck,openPin); if(opPos!==false){ epPos=myIndexOf(mySubStr(hsCheck,opPos+opLength,0),endP); if(epPos!==false){ textFound[] = mySubStr(hayStack,opPos+opLength,epPos); hayStack = mySubStr(hayStack,opPos+opLength+epPos+epLength,0); hsCheck = hayStack.toLowerCase(); } } }while((opPos!==false) && (epPos!==false)); return textFound; } Quote Link to comment Share on other sites More sharing options...
lemmin Posted August 15, 2008 Share Posted August 15, 2008 if(opPos!=false){ would evaluate to false if opPos = 0 or false (or anything that evaluates to false), but if(opPos!==false){ would evaluate to true if opPos = 0 (or any value other than false) Did you try the script without the extra '='? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.