You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2002/10/07 18:27:01 UTC

DO NOT REPLY [Bug 13367] New: - StringUtil enhancement

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13367>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=13367

StringUtil enhancement

           Summary: StringUtil enhancement
           Product: Commons
           Version: 1.0 Final
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Lang
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: roytmana@peacetech.com


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) {
      st1 = st1.trim();
      b1 = (st1.length() > 0);
    } 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 "";
  }

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>