Jump to content

how to use indexOf


optikalefx

Recommended Posts

So i found a way using keycodes to detect when the user types .com  but is there a way that when it detects .com to search backwards till it gets to a space and forwards till it gets to a space?

 

for example if you type  www.helloworld.com/boots.htm it would store into a string "www.helloworld.com/boots.htm"  So is there way to index back till it hits a space and then forward till it hits a space?

 

Link to comment
https://forums.phpfreaks.com/topic/95827-how-to-use-indexof/
Share on other sites

i appreciate the advice, i was looking for something more advance, i guess i should have said that.

 

I got it working. I add the event Listener to the document for keyUp.  (ff only).  And i take in event e as always.  I check to see if you hit space or enter, if so, reset the sentence back to blank.  elsewise check to see if you hit period because the charcode returns 2/4 instead of .  elsewise use String.fromCharCode to convert the unicode to the letter.  Now that returns all caps. so we send it to lowercase letters to be better readable.  We then dump to the js console to see what we get.

 

the only problem is the uppercase lowecase part.  if anyone can find a solution, id love it.  I cant seem to find a way to figure out what case the letter was when the user hit it.

 

document.addEventListener('keyup',detectWord,true);
function detectWord(e) {
   if(e.keyCode == 32 || e.keyCode == 13) {
      sentence = "";
   } else if(e.keyCode == 190) {
      sentence += "."
   } else {
      sentence += String.fromCharCode(e.keyCode);
   }
   sentence = sentence.toLowerCase();
      //dump(sentence+"\n");
}

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/95827-how-to-use-indexof/#findComment-490844
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.