Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Index in Java help
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Morice




PostPosted: 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
Sponsor
sponsor
wtd




PostPosted: 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




PostPosted: 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




PostPosted: 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]




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: