Results 1 to 5 of 5
Thread: Please need help
- 12-06-2011, 06:11 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
Please need help
Hi,
I have a String table : String [] title = {"One night at Paris", "Kisses from Paris", "A night with you"};
I want to implement a method that will search a word in this table and if it's find it to return the String.
For example :Java Code:public static String findTitle(String [] t) { String title = ""; String search = Clavier.lireString(); // I have a class Clavier that allow me to do input. for (int i = 0; i < t.length; i++) { if (t[i] != null) { if (search.equalsIgnoreCase(.....)) { System.out.println(t[i]); } } } }
If I type "nigth", I should have : "One night at Paris" and "A night with you".Last edited by pbrockway2; 12-06-2011 at 06:51 PM. Reason: code tags added
- 12-06-2011, 06:17 PM #2
Senior Member
- Join Date
- Feb 2010
- Location
- Waterford, Ireland
- Posts
- 748
- Rep Power
- 4
Re: Please need help
String (Java 2 Platform SE 5.0)
Don't forget the documentation
- 12-06-2011, 06:27 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 90
- Rep Power
- 0
Re: Please need help
Remember that "night" will never equal "A night with you" Check out String.contains
- 12-06-2011, 06:57 PM #4
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
Re: Please need help
Thank you for the advise. I'll check that and will let you know.
- 12-07-2011, 05:12 PM #5
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
Re: Please need help
String [] title = {"One night at Paris", "Kisses from Paris", "A night with you"};
String find = Clavier.lireString();
for (int i = 0; i < title.length; i++) {
if (t[i] != null) { // throw NullPointerException if null
if (t[i].toLowerCase.contains(find.toLowerCase)) {
System.out.println(t[i]);
}
}
}
Thank you for your help joyvitoro


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks