Results 1 to 2 of 2
  1. #1
    jayz is offline Member
    Join Date
    Aug 2009
    Posts
    1
    Rep Power
    0

    Default Word comparison in a Statement

    Hi,

    I'm trying to break the statement into word token and then compare. It seems to comapre and accept even a partial letter of an input word and set as true.

    Please advise how can I break this into tokens/ words and then compare word by word for example Roger(from input) should match with Roger(from another string) and so on.

    Java Code:
    public static void main(String[] args) {
          String input = "ro ger";
          String  another = "Roger Bell Technology Corporation";
    
          StringTokenizer inputToken = new StringTokenizer(input.toLowerCase());
          StringTokenizer anotherToken = new StringTokenizer(input.toLowerCase());
          int count = 0;int i=0;
                     
          while (inputToken.hasMoreTokens()) {
                    	    if(anotherToken.nextToken().contains(inputToken.nextToken())){i = i + 1;}
                count++;
                System.out.println("ivalue"+i);
                System.out.println("count"+count);
                if(count > 2){break;}
          }      
          if((i>2)||(i==2)){            
            System.out.println("true");
          }
        }

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    suggest to use String.split(" ") to get 2 string array
    use 2 for loops to compare the substring

    nextToken() would move the pointer, then, cant compare all substrings

Similar Threads

  1. list comparison
    By suprabha in forum New To Java
    Replies: 0
    Last Post: 07-17-2008, 12:01 PM
  2. String comparison
    By abhiN in forum New To Java
    Replies: 2
    Last Post: 04-09-2008, 05:47 AM
  3. Comparison of Strings
    By Cero.Uno in forum New To Java
    Replies: 3
    Last Post: 02-11-2008, 03:46 AM
  4. Date comparison
    By Rageagainst20 in forum New To Java
    Replies: 0
    Last Post: 12-19-2007, 07:34 PM
  5. String comparison
    By sireesha in forum New To Java
    Replies: 1
    Last Post: 12-18-2007, 01:16 AM

Posting Permissions

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