Author |
Message |
Morice
|
Posted: Thu Mar 30, 2006 3:49 pm Post subject: 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? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Thu Mar 30, 2006 3:59 pm Post subject: (No subject) |
|
|
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
|
Posted: Thu Mar 30, 2006 4:02 pm Post subject: (No subject) |
|
|
ok. I want to see if in a word is ther a letter tat im searching for. |
|
|
|
|
|
Corvillus
|
Posted: Thu Mar 30, 2006 5:52 pm Post subject: (No subject) |
|
|
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:
code: |
String s = "Hello, world!";
System.out.println(s.indexOf('o')); //outputs 4
|
|
|
|
|
|
|
[Gandalf]
|
Posted: Thu Mar 30, 2006 7:48 pm Post subject: (No subject) |
|
|
Or if you're talking about JavaScript...
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. |
|
|
|
|
|
|