• Post Reply Bookmark Topic Watch Topic
  • New Topic

Ignoring case-sensitivity  RSS feed

 
Sam Pauken
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone help me figure out how to ignore case-sensitivity for this code? I know I can use java.lang.equalsIgnoreCase, but I'm not sure how to apply it

>
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A common technique is to call quote.toLowerCase() so you don't have to think about uppercase at all.
 
Sam Pauken
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! Why does java.lang.equalsIgnoreCase not work where I have quote.toLowerCase()?

>
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Pauken wrote:Thanks! Why does java.lang.equalsIgnoreCase not work where I have quote.toLowerCase()?

Because it compares two Strings. You only have one String.
 
Robert D. Smith
Ranch Hand
Posts: 221
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What if you were to wrap it inside a Swich? Something like

For (I=0;...
Switch char(I)
Case a:
Case e:
Vowels++;

Just a thought.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert,
Welcome to CodeRanch!

The switch is definitely easier to read than the if statement. It doesn't solve the case insensitivity issue. You still have to use toLowerCase().chartAt() or 10 cases in the switch (upper and lower case vowels)
 
Robert D. Smith
Ranch Hand
Posts: 221
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:Robert,
Welcome to CodeRanch!

The switch is definitely easier to read than the if statement. It doesn't solve the case insensitivity issue. You still have to use toLowerCase().chartAt() or 10 cases in the switch (upper and lower case vowels)

My little snippet was intended to give the OP an idea on another way to approach the problem, and to improve readability. It wasn't intended to be a complete answer. I'm on my iPad and typing, let along coding, is a large PITA.

Oh, and thanks for the welcome.
 
Sam Pauken
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I haven't learned switching yet, though. I'll play with it more later if I have time. Thanks for your help.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
552
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert D. Smith wrote:My little snippet was intended to give the OP an idea on another way to approach the problem, and to improve readability. It wasn't intended to be a complete answer. I'm on my iPad and typing, let along coding, is a large PITA

No problem. It's a great suggestion. I probably should have commented that the second part of my reply was more for Sam.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you do use switch-case, be sure to add a comment. What you are doing is using fall‑through, and anybody seeing uncommented fall‑through will assume it is a mistake an may try to correct it by inserting break; statements.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!