com.alibaba.excel.util

类 StringUtils


  • public class StringUtils
    extends Object
    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.
    作者:
    Apache Software Foundation (ASF)
    • 字段详细资料

    • 方法详细资料

      • isEmpty

        public static boolean isEmpty(CharSequence cs)

        Checks if a CharSequence is empty ("") or null.

         StringUtils.isEmpty(null)      = true
         StringUtils.isEmpty("")        = true
         StringUtils.isEmpty(" ")       = false
         StringUtils.isEmpty("bob")     = false
         StringUtils.isEmpty("  bob  ") = false
         

        NOTE: This method changed in Lang version 2.0. It no longer trims the CharSequence. That functionality is available in isBlank().

        参数:
        cs - the CharSequence to check, may be null
        返回:
        true if the CharSequence is empty or null
      • isBlank

        public static boolean isBlank(CharSequence cs)

        Checks if a CharSequence is empty (""), null or whitespace only.

        Whitespace is defined by Character.isWhitespace(char).

         StringUtils.isBlank(null)      = true
         StringUtils.isBlank("")        = true
         StringUtils.isBlank(" ")       = true
         StringUtils.isBlank("bob")     = false
         StringUtils.isBlank("  bob  ") = false
         
        参数:
        cs - the CharSequence to check, may be null
        返回:
        true if the CharSequence is null, empty or whitespace only
      • isNotBlank

        public static boolean isNotBlank(CharSequence cs)

        Checks if a CharSequence is not empty (""), not null and not whitespace only.

        Whitespace is defined by Character.isWhitespace(char).

         StringUtils.isNotBlank(null)      = false
         StringUtils.isNotBlank("")        = false
         StringUtils.isNotBlank(" ")       = false
         StringUtils.isNotBlank("bob")     = true
         StringUtils.isNotBlank("  bob  ") = true
         
        参数:
        cs - the CharSequence to check, may be null
        返回:
        true if the CharSequence is not empty and not null and not whitespace only
        从以下版本开始:
        2.0, 3.0 Changed signature from isNotBlank(String) to isNotBlank(CharSequence)
      • equals

        public static boolean equals(CharSequence cs1,
                                     CharSequence cs2)

        Compares two CharSequences, returning true if they represent equal sequences of characters.

        nulls are handled without exceptions. Two null references are considered to be equal. The comparison is case sensitive.

         StringUtils.equals(null, null)   = true
         StringUtils.equals(null, "abc")  = false
         StringUtils.equals("abc", null)  = false
         StringUtils.equals("abc", "abc") = true
         StringUtils.equals("abc", "ABC") = false
         
        参数:
        cs1 - the first CharSequence, may be null
        cs2 - the second CharSequence, may be null
        返回:
        true if the CharSequences are equal (case-sensitive), or both null
        从以下版本开始:
        3.0 Changed signature from equals(String, String) to equals(CharSequence, CharSequence)
        另请参阅:
        Object.equals(Object)
      • regionMatches

        public static boolean regionMatches(CharSequence cs,
                                            boolean ignoreCase,
                                            int thisStart,
                                            CharSequence substring,
                                            int start,
                                            int length)
        Green implementation of regionMatches.
        参数:
        cs - the CharSequence to be processed
        ignoreCase - whether or not to be case insensitive
        thisStart - the index to start on the cs CharSequence
        substring - the CharSequence to be looked for
        start - the index to start on the substring CharSequence
        length - character length of the region
        返回:
        whether the region matched
      • isNumeric

        public static boolean isNumeric(CharSequence cs)

        Checks if the CharSequence contains only Unicode digits. A decimal point is not a Unicode digit and returns false.

        null will return false. An empty CharSequence (length()=0) will return false.

        Note that the method does not allow for a leading sign, either positive or negative. Also, if a String passes the numeric test, it may still generate a NumberFormatException when parsed by Integer.parseInt or Long.parseLong, e.g. if the value is outside the range for int or long respectively.

         StringUtils.isNumeric(null)   = false
         StringUtils.isNumeric("")     = false
         StringUtils.isNumeric("  ")   = false
         StringUtils.isNumeric("123")  = true
         StringUtils.isNumeric("१२३")  = true
         StringUtils.isNumeric("12 3") = false
         StringUtils.isNumeric("ab2c") = false
         StringUtils.isNumeric("12-3") = false
         StringUtils.isNumeric("12.3") = false
         StringUtils.isNumeric("-123") = false
         StringUtils.isNumeric("+123") = false
         
        参数:
        cs - the CharSequence to check, may be null
        返回:
        true if only contains digits, and is non-null
        从以下版本开始:
        3.0 Changed signature from isNumeric(String) to isNumeric(CharSequence), 3.0 Changed "" to return false and not true

Copyright © 2018–2021 Alibaba Group. All rights reserved.