private static String trimSpacesAndNulls(String value) {
        int len = value.length();
        int st = 0;

        while ((st < len) && (value.charAt(st) == ' ' || value.charAt(st) == 0 )) {
            st++;
        }
        while ((st < len) && (value.charAt(len - 1) == ' ' || value.charAt(len - 1) == 0)) {
            len--;
        }
        return ((st > 0) || (len < value.length())) ? value.substring(st, len) : value;
    }