Trims the supplied string. If the string is empty or null before or after
trimming, null is returned.

@param string the string to trim
@return the trimmed string or null
517518
@Nullable
    public static String trimToNull(@Nullable String string) {
        return Optional.ofNullable(string)
                .map(String::trim)
                .filter(StringUtils::isNotEmpty)
                .orElse(null);
    }
416707
public static boolean isBlank(@Nullable String string) {
        if (isEmpty(string)) {
            return true;
        }
        for (int i = 0; i < string.length(); i++) {
            if (!Character.isWhitespace(string.charAt(i))) {
                return false;
            }
        }
        return true;
    }
77528
private static String trimLeadingWhitespace(String string) {
        if (string.isEmpty()) {
            return string;
        }

        int start = 0;
        char c;

        for (int i = 0; i < string.length(); i++) {
            c = string.charAt(i);
            if (!Character.isWhitespace(c)) {
                start = i;
                break;
            }
        }

        if (start == 0) {
            return string;
        }

        return string.substring(start);
    }
601941
public static String nullIfEmpty(String s) {
      if (s != null && s.length() == 0) {
         return null;
      } else {
         return s;
      }
   }
886605
public static function getLastElementOfString($string, $separator)
    {
        $elements = self::getStringElements($string, $separator);

        /*
         * No elements?
         * Nothing to do
         */
        if (empty($elements)) {
            return null;
        }

        $element = Arrays::getLastElement($elements);

        return trim($element);
    }
966845
public static function stringToValue($string)
	{
		if($string == '')
		{
			return $string;
		}
		if(is_float($string))
		{
			return (float) $string;
		}
		if(is_int($string))
		{
			return (int) $string;
		}
		if(strtolower($string) == 'true')
		{
			return true;
		}
		if(strtolower($string) == 'false')
		{
			return false;
		}
		if(strtolower($string) == 'null')
		{
			return NULL;
		}
		
		return $string;
	}
731349
function( string ){
            string = $this.slash.clean( string );

            if( string[ 0 ] === $this.slash.get()) string = string.substr( 1 );
            if( string[ string.length -1 ] === $this.slash.get()) string = string.substr( 0, string.length -1 );

            return string;
        }
528319
private static String trim(String string) {
        String result = string.trim();
        if (result.startsWith("\"") && result.endsWith("\"") && result.length() > 1) {
            result = result.substring(1, result.length() - 1);
        }
        return result;
    }
786830
public static function trimStringArray(array $string, $recursion = true)
    {
        foreach ($string as $key => $value) {
            if (is_array($value) && $recursion) {
                $string[$key] = self::trimStringArray($value);
            } elseif (!is_array($value)) {
                $string[$key] = trim($value);
            }
        }

        return $string;
    }
100254
private function separateSelectString(string $string)
    {
        if (false === strpos($string, '(')) {
            return array_map('trim', explode(',', $string));
        }

        $opened = $closed = 0;
        $cnt = mb_strlen($string);
        $arrayStrings = [];
        $substring = '';

        for ($i = 0; $i < $cnt; $i++) {
            $substring .= $string[$i];
            if ('(' === $string[$i]) {
                $opened++;
            } elseif (')' === $string[$i]) {
                $closed++;
            } elseif (',' === $string[$i] && $opened === $closed) {
                $arrayStrings[] = trim($substring);
            }
        }
        $arrayStrings[] = trim($substring);

        return $arrayStrings;
    }
1165604
public static function isEmpty($string)
    {
        if (!self::isValid($string) &&
            null !== $string
        ) {
            return false;
        }

        return ($string === null || $string === '');
    }
865163
public static String truncate(String string, int maxLength) {
        if (string.length() > maxLength) {
            return string.substring(0, maxLength);
        }
        return string;
    }
503631
protected String beforeParse(String string)
	{
		if (preParseCallback == null)
		{
			return string;
		}
		
		return preParseCallback.process(string);
	}
886598
public static String trimWhitespaceToNull(final String s) {
        final String result = trimWhitespace(s);
        return StringUtils.isEmpty(result) ? null : s;
    }
1331591
public final static String trim(String value)
    {
        String result = null;
        if (null != value)
        {
            result = value.trim();
        }

        return result;
    }
378600
public static String 
    trimRight( String string ) 
    {
    	for( int i = string.length(); i > 0; --i )
    	{
    		if( string.charAt(i-1) != ' '
    		&& string.charAt(i-1) != '\t'
    		&& string.charAt(i-1) != '\n'
    		&& string.charAt(i-1) != '\r' ) 
    		{    			
    			return i == string.length() ? string : 
    			                              string.substring( 0, i );
    		}
    	}
    	return "";
    }
300867
public static String trim(String str, String arg) {
        if (str == null || arg == null) {
            throw new NullPointerException("str or arg must not be null");
        }

        while (str.startsWith(arg)) {
            str = str.substring(arg.length());
        }

        while (str.endsWith(arg)) {
            str = str.substring(0, str.length() - arg.length());
        }
        return str;
    }