Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

String.toLowerCase()  RSS feed

 
henri henri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have film titles that begin with the name of the film followed by ",The" if the original name begins with the. Example: Village, The
When a user wants to search the collection for a film title, he or she will naturaly type in The Village, so I have some code that switches the word The around, then switches it back to see if the title is in the collection. My variable "the" holds the literal The which is capitalized, but the user may enter the, uncapitalized. Is there an ingenious way to use toLowerCase() somewhere in my code to catch both possibilites?

key: is the a HashMap key representing a film title.
title: is the String recieved via the TextField
the: is "The "

 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep what the user enters, to use in messages to the user,
but convert everything the user enters to uppercase and
work entirely within uppercase:

[ October 19, 2005: Message edited by: Jeff Albrechtsen ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you've ironed out case differences, look at String.startsWith() or indexOf(). You probably only want to modify titles when the user enters "The Chase" and not "O Brother Where Art Thou"
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!