Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / November 2005

Tip: Looking for answers? Try searching our database.

IgnoreCase, how do i do it?

Thread view: 
ste1986 - 19 Nov 2005 22:21 GMT
I am having trouble getting my program to ignore how information is entered
(upper/lower case letters). i have been told i have to use IgnoreCase but i
cant get it to work.

below is the line of code where i need the IgnoreCase to ignore how
"desktop" is written (Desktop, desktop, dESktOP etc...)
if  (type != "desktop")
Andrew Thompson - 19 Nov 2005 23:44 GMT
> I am having trouble getting my program to ignore how information is entered
> (upper/lower case letters). i have been told i have to use IgnoreCase but i
[quoted text clipped - 3 lines]
> "desktop" is written (Desktop, desktop, dESktOP etc...)
> if  (type != "desktop")

if ( !type.toLowerCase().equals("desktop") )

Signature

Andrew Thompson
physci, javasaver, 1point1c, lensescapes - athompson.info/andrew
Currently accepting short and long term contracts - on Earth.

Rhino - 20 Nov 2005 00:01 GMT
>> I am having trouble getting my program to ignore how information is
>> entered
[quoted text clipped - 7 lines]
>
> if ( !type.toLowerCase().equals("desktop") )

Or:

if (!type.equalsIgnoreCase().equals("desktop"))

The mistake you made in your original code is to use the = operator to
compare Strings. The correct technique for comparing Strings is to use the
methods in the String class.

Rhino
Oliver Wong - 22 Nov 2005 17:31 GMT
>>> I am having trouble getting my program to ignore how information is
>>> entered
[quoted text clipped - 15 lines]
> compare Strings. The correct technique for comparing Strings is to use the
> methods in the String class.

   Rhino is correct in saying that you should use methods like "equals" or
"equalsIgnoreCase" to compare strings, instead of the "==" or "!=" operator,
but his/her code has a small mistake (probably a typo). It should read:

   if (!type.equalsIgnoreCase("desktop"))

   - Oliver
DrMatrix - 27 Nov 2005 19:05 GMT
> >>> I am having trouble getting my program to ignore how information is
> >>> entered
[quoted text clipped - 23 lines]
>
>     - Oliver

Or better yet use:

  if ( !"desktop".equalsIgnoreCase(type) )

This will work even if type == null.  if
(!type.equalsIgnoreCase("desktop")) will get a NullPointerException when
type == null.
Knute Johnson - 20 Nov 2005 03:44 GMT
>> I am having trouble getting my program to ignore how information is
>> entered
[quoted text clipped - 7 lines]
>
> if ( !type.toLowerCase().equals("desktop") )

if (!type.equalsIgnoreCase("desktop"))

Signature

Knute Johnson
email s/nospam/knute/

Roedy Green - 20 Nov 2005 02:18 GMT
>if  (type != "desktop")

see http://mindprod.com/jgloss/gotchas.html#COMPARISON
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.