Details
Description
Could you please add two methods to StringUtils. They are very simple but I
find them very usefull in day to day programming (isn't "Commons-Lang" a
collection of simple utilities for some very simple but very common cases )
1. String trimNull(String str) to return trimmed str or null if str == null or
str.trim() is blank. Very often I want to treat blank as null (actually more
often than null as "")
2. String join(String str1, String str2, String delim). This should join str1
and 2 and put delimiter in between only if both are not null (blank?) if one or
both are null (blank) delimiter should not be inserted
Please see examles below
public static String trimNull(String value)
{ if (value == null) return null; else if (value.length() > 0) value = value.trim(); if (value.length() > 0) return value; else return null; } public static String join(String st1, String st2, String sep) {
boolean b1, b2;
if (st1 != null)
else b1 = false;
if (st2 != null)
{ st2 = st2.trim(); b2 = (st2.length() > 0); }else b2 = false;
if (b1)
if (b2) return st1 + ((sep == null) ? st2 : sep + st2);
else return st1;
else
if (b2) return st2;
else return "";
}