-3

I have to make a function that finds when "www." Appears in a string, for example "Hey dude, check this thing: www.example.com/". I want it to determine when the url starts(in this case it would be the 28th character in the string). I tried this:

var wwwPos = new Number;
function findURL(message){
splitStr = message.split ("");
for(var i = 0; i <splitStr.length; i++){
     if(splitStr[i] == "w" && splitStr[i+1] == "w" && splitStr[i+2] == "w" && splitStr[i+3] == "."){
          wwwPos=i
          break;
     }
}
}

But it didn't work...

Maigol
  • 7
  • 5

1 Answers1

0
var str = 'Hi Dude Check Out: www.example.com';
str.indexOf('www.'); // 19 because the first w in www. is at position 19
Akyuna Akish
  • 147
  • 1
  • 7