• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Beginnerquestion about if (personName==null || personName.equals(""))
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Beginnerquestion about if (personName==null || personName.equals(""))


  • Subject: Re: Beginnerquestion about if (personName==null || personName.equals(""))
  • From: Lachlan Deck <email@hidden>
  • Date: Sat, 8 Sep 2007 04:52:31 +1000

Hi there,

On 07/09/2007, at 7:44 PM, Rainer User wrote:

i am new at the webobjects-dev maillist and new to webobjects too.

I am reading the white printed book "Webobjects 5, Web Applications", from Apple, it was included in the Webobjects Package of my Webobject-Box.

On Page 84 i found an example where a funktion trys to detect if a variable named "personName" [type of it is "String"] is empty or not.

The substantial Code says:

if (personName==null || personName.equals(""))
{
	return(true);
}
else
{
	return(false);
}

Further to what others have said it is also sometimes helpful to test for whitespace strings. e.g., " " and treat them as empty also. And it's often helpful to trim a string of surrounding whitespace...


public static boolean isEmptyString(String value) {
	return value == null || value.matches( "^\\s*$" );
}

public void setFirstName(String firstName) {
	if (isEmptyString(firstName))
		this.firstName = null;
	else
		this.firstName = firstName.trim();
}

with regards,
--

Lachlan Deck



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Beginnerquestion about if (personName==null || personName.equals(""))
      • From: Kieran Kelleher <email@hidden>
References: 
 >Beginnerquestion about if (personName==null || personName.equals("")) (From: Rainer User <email@hidden>)

  • Prev by Date: Re: Beginnerquestion about if (personName==null || personName.equals(""))
  • Next by Date: Re: Beginnerquestion about if (personName==null || personName.equals(""))
  • Previous by thread: Re: Beginnerquestion about if (personName==null || personName.equals(""))
  • Next by thread: Re: Beginnerquestion about if (personName==null || personName.equals(""))
  • Index(es):
    • Date
    • Thread