Removes control characters (char <= 32) from both ends returning an empty String ("") if the String is empty ("") after the trim or if it is null. : String ASCII « Data Type « Java






Removes control characters (char <= 32) from both ends returning an empty String ("") if the String is empty ("") after the trim or if it is null.

  
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.TimeZone;


/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */




/**
 * <p>Operations on {@link java.lang.String} that are
 * <code>null</code> safe.</p>

 *
 * @see java.lang.String
 * @author <a href="http://jakarta.apache.org/turbine/">Apache Jakarta Turbine</a>
 * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a>
 * @author Daniel L. Rall
 * @author <a href="mailto:gcoladonato@yahoo.com">Greg Coladonato</a>
 * @author <a href="mailto:ed@apache.org">Ed Korthof</a>
 * @author <a href="mailto:rand_mcneely@yahoo.com">Rand McNeely</a>
 * @author Stephen Colebourne
 * @author <a href="mailto:fredrik@westermarck.com">Fredrik Westermarck</a>
 * @author Holger Krauth
 * @author <a href="mailto:alex@purpletech.com">Alexander Day Chaffee</a>
 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 * @author Arun Mammen Thomas
 * @author Gary Gregory
 * @author Phil Steitz
 * @author Al Chou
 * @author Michael Davey
 * @author Reuben Sivan
 * @author Chris Hyzer
 * @author Scott Johnson
 * @since 1.0
 * @version $Id: StringUtils.java 635447 2008-03-10 06:27:09Z bayard $
 */
public class Main {

  /**
   * <p>Removes control characters (char &lt;= 32) from both
   * ends of this String returning an empty String ("") if the String
   * is empty ("") after the trim or if it is <code>null</code>.
   *
   * <p>The String is trimmed using {@link String#trim()}.
   * Trim removes start and end characters &lt;= 32.
   * To strip whitespace use {@link #stripToEmpty(String)}.</p>
   *
   * <pre>
   * StringUtils.trimToEmpty(null)          = ""
   * StringUtils.trimToEmpty("")            = ""
   * StringUtils.trimToEmpty("     ")       = ""
   * StringUtils.trimToEmpty("abc")         = "abc"
   * StringUtils.trimToEmpty("    abc    ") = "abc"
   * </pre>
   *
   * @param str  the String to be trimmed, may be null
   * @return the trimmed String, or an empty String if <code>null</code> input
   * @since 2.0
   */
  public static String trimToEmpty(String str) {
      return str == null ? "" : str.trim();
  }
}

   
    
  








Related examples in the same category

1.Checks whether the character is ASCII 7 bit.
2.Checks whether the character is ASCII 7 bit printable.
3.Checks whether the character is ASCII 7 bit control.
4.Checks whether the character is ASCII 7 bit alphabetic.
5.Checks whether the character is ASCII 7 bit alphabetic upper case.
6.Checks whether the character is ASCII 7 bit alphabetic lower case.
7.Checks whether the character is ASCII 7 bit numeric.
8.Checks whether the character is ASCII 7 bit numeric and character.
9.Allow text containing mostly ASCII characters to be decipherable on an ASCII terminal without decoding.
10.Removes control characters (char <= 32) from both ends returning null if the String is empty ("") after the trim or if it is null
11.Get 7-bit ASCII character array from input String.
12.Test if the character is a digit <digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
13.Test if the current character is a digit <digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
14.Test if the current character is a new line.
15.Test if the current character is a space.
16.Test if the current character is an Alpha character : <alpha> ::= [0x41-0x5A] | [0x61-0x7A]
17.Test if the current character is an Ident character
18.Test if the current character is equal to a specific character.
19.Test if the current string is a digit <digit> ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
20.Removes spaces (char <= 32) from both start and ends of this bytes array
21.Removes spaces (char <= 32) from end of this String with escape, handling null by returning null
22.Removes spaces (char <= 32) from end of this String, handling null by returning null
23.Removes spaces (char <= 32) from end of this array by index, handling null by returning null
24.Removes spaces (char <= 32) from end of this array ny position, handling null by returning null
25.Removes spaces (char <= 32) from end of this array, handling null by returning null
26.Removes spaces (char <= 32) from start of this String, handling null by returning null
27.Removes spaces (char <= 32) from start of this array, handling null by returning null
28.Thansform an array of ASCII bytes to a string. the byte array should contains only values in [0, 127].