
-----------------------------------
Morice
Thu Mar 30, 2006 3:49 pm

Index in Java help
-----------------------------------
Is there an index function in Java script like the one in Turing tat i can use for a hangman game?

-----------------------------------
wtd
Thu Mar 30, 2006 3:59 pm


-----------------------------------
Javascript is not Java.

Also, for those not familiar with Turing's "index" function, please provide a description of what you wish to accomplish.

-----------------------------------
Morice
Thu Mar 30, 2006 4:02 pm


-----------------------------------
ok. I want to see if in a word is ther a letter tat im searching for.

-----------------------------------
Corvillus
Thu Mar 30, 2006 5:52 pm


-----------------------------------
I'd guess you're looking for the String.indexOf() method, which returns the index of  the first occurence of either a given character or a given string within a string, or -1 for no occurence. For example:

String s = "Hello, world!";
System.out.println(s.indexOf('o')); //outputs 4


-----------------------------------
[Gandalf]
Thu Mar 30, 2006 7:48 pm


-----------------------------------
Or if you're talking about JavaScript...
var str="Java is not JavaScript"
document.write(str.indexOf("Java"))
The method works the exact same way as the Java example posted by Corvillus.
