I have actually used code that treats a blank string as null. The typical
example is input from an HTML form that sends in "", but you want to store
null in the object model.

I propose we solve this debate by adding *2* new methods to StringUtils:

trimToNull(String str) {
if (str == null) return null;
str = str.trim();
if (str.length() == 0) return null;
return str;

trimToBlank(String)
if (str == null) return "";
return str.trim();

These seem to complement the existing trim() method, and don't feel out of
place to me.
Stephen

----- Original Message -----
From: "Henri Yandell" <[EMAIL PROTECTED]>
>
> Which is StringUtils.trim. Already there.
>
> Like Dave, I'm not sure I can see converting "" to null as a highly common
> thing to do. In fact, I'd expect people to want the reverse more often
> [which I suspect Dave might like}, convert any null passed in into "".
>
> Which is StringUtils.trim(StringUtils.defaultString(..)) or some such. A
> bit longwinded.
>
> Hen
>
> On Wed, 22 Jan 2003 [EMAIL PROTECTED] wrote:
>
> >
> > Hi,
> >
> > I'm just a lurker here, but my preference would be to return an empty
> > string rather than null when the string consists of just whitespace. I
find
> > it to be annoying to always have to check for null. In fact, I very
rarely
> > initialize a String to null, but generally initialize to "".
> >
> > Just my 2 cents,
> > Dave Derry
> >
> >
> >
> >
> >
> >                       "Leonardo
> >                       Quijano                  To:
<[EMAIL PROTECTED]>
> >                       Vincenzi"                cc:
> >                       <lquijano@pnudcr         Subject: [PATCH][LANG]
StringUtils.trimNull(String)
> >                       .com>
> >
> >                       01/22/2003 01:38
> >                       PM
> >                       Please respond
> >                       to "Jakarta
> >                       Commons
> >                       Developers List"
> >
> >
> >
> >
> >
> > I added a new method to StringUtils. It trims a string, returning null
if
> > the string only has whitespace.
> >
> > Bug#: 13367
> >
> > Leonardo Quijano
> > [EMAIL PROTECTED]
> > (See attached file: patchfile.txt)--
> > To unsubscribe, e-mail:   <
> > mailto:[EMAIL PROTECTED]>
> > For additional commands, e-mail: <
> > mailto:[EMAIL PROTECTED]>
> >
> >
> >
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to