• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Letter by Letter checking

 
Lawrence Buensalida
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to check every letter of a word that the user typed and compare it to another word?
(Example: Comparing "Rain" to "Bell" by checking if the first letter, "R", is equal to "B". Then, going to the next letter, "A" and "E"...and so on.)
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is possible. I just don't have access to the code that i had written before, but I had a TextFeild that I would allow numbers, and since MIDP 1.0 doesn't have floating points, I would inject a decimal into the number, and display the new number in a StringItem.

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My vague memory thinks that I used an ItemChangeListener for the trick.

Mark
 
Lawrence Buensalida
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestion.

By the way, I saw String.compareTo() and String.charAt() in the MIDP 2.0 documentation. Will that help? I don't know how to use it, do you have any idea?

I'm also considering your suggestion because I don't know much in J2ME field. Again, thank you.

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, compareTo is what you would use. This is from the Comparable interface, which is the same in J2SE.

It will return a 1 if greater than, 0 if equal, and -1 if less than.

The charAt will give you the specific character at the specific index given.

If you are just looking at comparing two strings to alphabetize things, then just use the whole word and the compareTo method.

If you want to compare letter at a time as the user enters it, then use the ItemStateChangeListener.

Mark

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic