Results 1 to 2 of 2
Thread: Word comparison in a Statement
- 08-08-2009, 04:08 AM #1
Member
- Join Date
- Aug 2009
- Posts
- 1
- Rep Power
- 0
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"); } }
- 08-08-2009, 06:34 AM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
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
-
list comparison
By suprabha in forum New To JavaReplies: 0Last Post: 07-17-2008, 11:01 AM -
String comparison
By abhiN in forum New To JavaReplies: 2Last Post: 04-09-2008, 04:47 AM -
Comparison of Strings
By Cero.Uno in forum New To JavaReplies: 3Last Post: 02-11-2008, 02:46 AM -
Date comparison
By Rageagainst20 in forum New To JavaReplies: 0Last Post: 12-19-2007, 06:34 PM -
String comparison
By sireesha in forum New To JavaReplies: 1Last Post: 12-18-2007, 12:16 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks