Howdy,
if (test == null || test.trim().length() == 0 ) { } is simpler.
/Robert
Frank Zammetti wrote:
I've always done
if (test == null || test.trim().equalsIgnoreCase("")) { }
(I'm anal about always using equalsIgnoreCase unless I know for sure
that case sensitivity is required). No need to do anything more
complex than that in my experience. "Always do the simplest thing that
will work".
Frank
From: Robert Bateman <[EMAIL PROTECTED]>
Reply-To: "Tomcat Users List" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <[EMAIL PROTECTED]>
Subject: Re: how to check if a String is empty?
Date: Fri, 18 Jun 2004 12:58:30 -0400
Wouldn't test.trim().length() be a better test? length() after trm
would
tell you if non white-space was left.
Bob
On Thursday 24 June 2004 12:30 pm, Peter Guyatt wrote:
> Hi There,
>
> You could do the check test.length() > 0
>
> Pete
>
> -----Original Message-----
> From: Carl Olivier [mailto:[EMAIL PROTECTED]
> Sent: 24 June 2004 17:18
> To: 'Tomcat Users List'
> Subject: RE: how to check if a String is empty?
>
>
> There is a trim() funtion in java.lang.String
>
> ?
>
> -----Original Message-----
> From: Marten Lehmann [mailto:[EMAIL PROTECTED]
> Sent: 24 June 2004 06:20 PM
> To: 'Tomcat Users List'
> Subject: how to check if a String is empty?
>
>
> Hello,
>
> maybe this is not the perfect group for my question, but as my problem
> appears at the development of JSPs and tomcat is concerned with
that, I
> hope you can answer it.
>
> I often see the condition
>
> String test = req.getParameter("test");
>
> if (test == null) {
> /* string is empty */
> } else {
> /* string contains something */
> }
>
> But if test contains just blanks and other whitespaces, it's not null,
> but doesn't contain usable data anyhow. How can I check if a string
> contains whitespaces only? I though of something like
>
> if (test == null || test.trim().equals("")) {
> }
>
> but there's no trim()-function, right? How do you solve this problem?
> With whitespaces I mean blanks, tabs and newlines.
>
> Regards
> Marten
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
Make the most of your family vacation with tips from the MSN Family
Travel Guide! http://dollar.msn.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]