You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Robert Bateman <bo...@sequoiallc.com> on 2004/06/18 18:58:30 UTC

Re: how to check if a String is empty?

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:carl@zero-one.co.za]
> 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:lehmann@cnm.de]
> 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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org