943,553 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1945
  • Java RSS
Mar 13th, 2009
0

String search methods indexOf and lastIndexOf

Expand Post »
I need help on this: Write your own versions of String search methods indexOf and lastIndexOf.

Hope you could help.thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
enitsirc is offline Offline
3 posts
since Mar 2009
Mar 13th, 2009
0

Re: String search methods indexOf and lastIndexOf

I don't think so, but java docs can. Check the java docs for the methods and try implement the methods yourself those are some pretty basic ones.
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Mar 13th, 2009
0

Re: String search methods indexOf and lastIndexOf

i'm a beginner on programing that is why i dont know much about this.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
enitsirc is offline Offline
3 posts
since Mar 2009
Mar 13th, 2009
0

Re: String search methods indexOf and lastIndexOf

Help has already been offered if care enough to look for it.
Reputation Points: 485
Solved Threads: 89
Posting Shark
verruckt24 is offline Offline
944 posts
since Nov 2008
Mar 13th, 2009
0

Re: String search methods indexOf and lastIndexOf

maybe you don't know much (yet) but this is exactly the reason you are given assignments like this, to get to know the syntaxis and regulary used methods and to create your own implementation of them.

asking us to just give you the code would mean that in a week, you still have to say "I don't know much, which is why I need help".

try to understand what indexOf() and lastIndexOf() do:
a String - object can be seen as an array of chars, so the indexOf("substring") will give you the 'index' of the start of the given substring within the original String.

for instance:
Java Syntax (Toggle Plain Text)
  1. String ob = "the first String";
  2. System.out.println("place: " + ob.indexOf("St"));
  3. System.out.println("place: " + ob.indexOf("notPresent"));

just run this code, see what it does, and interprete the results you get.

I take it that lastIndexOf("") will be quite clear after the answers you've already been given.

once you figured out what the code I've posted above does, it should be quite easy to write a new implementation of this methods
Reputation Points: 919
Solved Threads: 353
Nearly a Posting Maven
stultuske is offline Offline
2,471 posts
since Jan 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: <identifier>expecter ERROR
Next Thread in Java Forum Timeline: how to compare a string to an integer in java





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC