Results 1 to 5 of 5
  1. #1
    myves is offline Member
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default 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.

    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]);
                 } 
            }
          }
    }
    For example :
    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

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default Re: Please need help

    String (Java 2 Platform SE 5.0)

    Don't forget the documentation

  3. #3
    joeyvitoro is offline Member
    Join Date
    Oct 2011
    Posts
    90
    Rep Power
    0

    Default Re: Please need help

    Remember that "night" will never equal "A night with you" Check out String.contains

  4. #4
    myves is offline Member
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default Re: Please need help

    Thank you for the advise. I'll check that and will let you know.

  5. #5
    myves is offline Member
    Join Date
    Dec 2011
    Posts
    3
    Rep Power
    0

    Default 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •