On Thu, 23 Jan 2003, Stephen Colebourne wrote:

> trimToNull(String str) {

if-null: null
trim.
if-empty: null

> trimToBlank(String)
if-null: ""
trim.

to complement the existing:

> trim(String)
if-null: null
trim.

> clean(String)
if-null: ""
trim.

>From this we see that my off-hand suggestion of something with the
functinality of trimToBlank was stupid, we already have it: clean().

So we're facing just the addition of trimToNull.

if-null: null
trim.
if-empty: null

The first two lines are the same as trim(x), but we have no way of doing
the latter. Should this be an ifEmpty(x,y) method?

ie)

public static String ifEmpty(String str, Object value) {
    if("".equals(str)) {
        return value;
    } else {
        return str;
    }
}

changing the desired code to:

String str = ...
String ret = StringUtils.ifEmpty( StringUtils.trim(str), null );

Any views?

It may be that the method wants to be ifEmptyOrNull (?)

Hen


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

Reply via email to