Howdy,

Instead of comparing to a zero length string, test.trim().equala(""),
try test.trim().length() == 0

/Robert

Carl Olivier wrote:

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]

---------------------------------------------------------------------
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]



Reply via email to