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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.