Apaches StringUtils class

org.apache.commons.lang
Class StringUtils

java.lang.Object
  org.apache.commons.lang.StringUtils

--------------------------------------------------------------------------------
public class StringUtils
extends Object
Operations on String that are null safe. 字符串是null安全的,不会抛出NullPointerException,都做了相应的处理。
IsEmpty/IsBlank - checks if a String contains text
IsEmpty/IsBlank – 检查字符串是否有内容。
Trim/Strip - removes leading and trailing whitespace
Trim/Strip – 删除字符串开始和结尾的空白符。
Equals - compares two strings null-safe
Equals – 比较两个字符串null安全。
IndexOf/LastIndexOf/Contains - null-safe index-of checks
IndexOf/LastIndexOf/Contains – null安全的索引检查。
IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut - index-of any of a set of Strings
IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut – 字符串集合索引检查。
ContainsOnly/ContainsNone - does String contains only/none of these characters
ContainsOnly/ContainsNone – 字符在字符串中出现一次或一次也没有出现。
Substring/Left/Right/Mid - null-safe substring extractions
Substring/Left/Right/Mid – null安全子串的提取。
SubstringBefore/SubstringAfter/SubstringBetween - substring extraction relative to other strings
SubstringBefore/SubstringAfter/SubstringBetween – 子串提取依赖其它字符串。
Split/Join - splits a String into an array of substrings and vice versa
Split/Join – 字符串拆分为子串的字符串数组,反之亦然。
Remove/Delete - removes part of a String
Remove/Delete – 删除部分字符串。
Replace/Overlay - Searches a String and replaces one String with another
Replace/Overlay – 替换字符串的部分字符。
Chomp/Chop - removes the last part of a String
Chomp/Chop – 删除字符串最后的字符。
LeftPad/RightPad/Center/Repeat - pads a String
LeftPad/RightPad/Center/Repeat – 补字符串。
UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize - changes the case of a String
UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize – 改变字符串的大小写。
CountMatches - counts the number of occurrences of one String in another
CountMatches – 计算一个字符或字符串在另外一个字符串出现的次数。
IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable - checks the characters in a String
IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable – 判断字符是否在字符串中。
DefaultString - protects against a null input String
DefaultString –null安全,null转换为字符串。
Reverse/ReverseDelimited - reverses a String
Reverse/ReverseDelimited – 反转字符串。
Abbreviate - abbreviates a string using ellipsis
Abbreviate – 缩写字符串用省略符。
Difference - compares two Strings and reports on their differences
Difference – 比较两个字符串并且返回不同。
LevensteinDistance - the number of changes needed to change one String into another
LevensteinDistance – 一个字符串改变为另一个字符串需要改变的数量。
The StringUtils class defines certain words related to String handling.
StringUtils类是对字符串的处理。
null – null 空
empty - a zero-length string ("") 长度为0的字符串
space - the space character (' ', char 32) 间隔符
whitespace - the characters defined by Character.isWhitespace(char) 空格符
trim - the characters <= 32 as in String.trim()去掉字符串两边字符<=32
Version:
$Id: StringUtils.java 492377 2007-01-04 01:20:30Z scolebourne $
 
Field Summary字段摘要
 
static String
 EMPTY
          The empty String "".空字符串。
 
static int
 INDEX_NOT_FOUND
          Represents a failed index search. 声明失败索引。
 

 
Constructor Summary构造方法摘要
 
StringUtils()
          StringUtils instances should NOT be constructed in standard programming.StringUtils 所有方法都是静态方法,不能在程序中对其进行构造。
 
 

 
Method Summary方法摘要
 
static String
 abbreviate(String str, int maxWidth)
Abbreviates a String using ellipses.
取得字符串的缩写,str:处理的字符串,maxWidth:宽度,从第一个字符开始[1,maxWidth),类似于substring(),返回一个新的字符串,它是此字符串的一个子字符串。
 
static String
 abbreviate(String str, int offset, int maxWidth)
          Abbreviates a String using ellipses.
取得字符串的缩写,str:处理的字符串,maxWidth:宽度,从第offset个字符开始[offset,axWidth),类似于substring(),返回一个新的字符串,它是此字符串的一个子字符串。
 
static String
 capitalise(String str)
          Deprecated. Use the standardly named capitalize(String). Method will be removed in Commons Lang 3.0.
过时了.用 capitalize(String),在Commons Lang 3.0已经没有此方法了。
 
static String
 capitaliseAllWords(String str)
          Deprecated. Use the relocated WordUtils.capitalize(String). Method will be removed in Commons Lang 3.0.
过时了. 在Commons Lang 3.0已经没有此方法了。
 
static String
 capitalize(String str)
          Capitalizes a String changing the first letter to title case as per Character.toTitleCase(char).
将str手写字母大写,用于名称、头衔等
 
static String
 center(String str, int size)
          Centers a String in a larger String of size size using the space character (' ').
产生一个字符串返回,该字符串长度等于size,str位于新串的中心,其他位置补空格。
如果str为null,则返回null
如果size小于str的长度,则返回str本身
 
static String
 center(String str, int size, char padChar)
          Centers a String in a larger String of size size.
产生一个字符串返回,该字符串长度等于size,str位于新串的中心,其他位置补字符padChar。
如果str为null,则返回null
如果size小于str的长度,则返回str本身
 
static String
 center(String str, int size, String padStr)
          Centers a String in a larger String of size size.
产生一个字符串返回,该字符串长度等于size,str位于新串的中心,其他位置补字符串padStr。
如果str为null,则返回null
如果size小于str的长度,则返回str本身
 
static String
 chomp(String str)
          Removes one newline from end of a String if it's there, otherwise leave it alone.
 以单个词为单位的反转
str=”I am yuanyuan !”;
chomp(str)=”! yuanyuan an  I”;
 
static String
 chomp(String str, String separator)
          Removes separator from the end of str if it's there, otherwise leave it alone.
 以单个词为单位的反转,从separator开始
str=”I am yuanyuan !”;
chomp(str ,”!”)=” yuanyuan an  I !”;
 
static String
 chompLast(String str)
          Deprecated. Use chomp(String) instead. Method will be removed in Commons Lang 3.0.
过时了.在Commons Lang 3.0已经没有此方法了
 
static String
 chompLast(String str, String sep)
          Deprecated. Use chomp(String,String) instead. Method will be removed in Commons Lang 3.0.
过时了.在Commons Lang 3.0已经没有此方法了
 
static String
 chop(String str)
          Remove the last character from a String.
去掉字符串str的最后一个字符。如果字符串以"\r\n"结尾,则去掉它们。
 
static String
 chopNewline(String str)
          Deprecated. Use chomp(String) instead. Method will be removed in Commons Lang 3.0.
过时了.在Commons Lang 3.0已经没有此方法了
 
static String
 clean(String str)
          Deprecated. Use the clearer named trimToEmpty(String). Method will be removed in Commons Lang 3.0.
过时了.在Commons Lang 3.0已经没有此方法了
 
static String
 concatenate(Object[] array)
          Deprecated. Use the better named join(Object[]) instead. Method will be removed in Commons Lang 3.0.
过时了.在Commons Lang 3.0已经没有此方法了
 
static boolean
 contains(String str, char searchChar)
          Checks if String contains a search character, handling null.
当此字符串包含指定的字符searchChar 值序列时,返回 true;处理null。
 
static boolean
 contains(String str, String searchStr)
          Checks if String contains a search String, handling null.
当此字符串包含指定的字符串searchStr 值序列时,返回 true;处理null。
 
static boolean
 containsIgnoreCase(String str, String searchStr)
          Checks if String contains a search String irrespective of case, handling null.
当此字符串包含指定的字符串searchStr 值序列时,忽略大小写,返回 true;处理null。
 
static boolean
 containsNone(String str, char[] invalidChars)
          Checks that the String does not contain certain characters.
判断是否字符串str不包含字符数组invalidChars中的字符,如果含有则返回false。
 
static boolean
 containsNone(String str, String invalidChars)
          Checks that the String does not contain certain characters.
判断是否字符串str不包含字符串invalidChars,如果含有则返回false。
 
static boolean
 containsOnly(String str, char[] valid)
          Checks if the String contains only certain characters.
判断是否字符串str包含字符数组valid中的字符,如果含有则返回true。
 
static boolean
 containsOnly(String str, String validChars)
          Checks if the String contains only certain characters.
判断是否字符串str包含字符串invalidChars,如果含有则返回true。
 
static int
 countMatches(String str, String sub)
          Counts how many times the substring appears in the larger String.
计算字符串sub在字符串str中出现的次数。如果str为null或"",则返回0
 
static String
 defaultIfEmpty(String str, String defaultStr)
          Returns either the passed in String, or if the String is empty or null, the value of defaultStr.
如果str不是空或者null,返回str,否则返回defaultStr。
 
static String
 defaultString(String str)
          Returns either the passed in String, or if the String is null, an empty String ("").
如果str不是空返回str,否则返回""。
 
static String
 defaultString(String str, String defaultStr)
          Returns either the passed in String, or if the String is null, the value of defaultStr.
如果str不为空,返回str,否则返回defaultStr
 
static String
 deleteSpaces(String str)
          Deprecated. Use the better localized deleteWhitespace(String). Method will be removed in Commons Lang 3.0.
过时了.在Commons Lang 3.0已经没有此方法了
 
static String
 deleteWhitespace(String str)
          Deletes all whitespaces from a String as defined by Character.isWhitespace(char).
删除字符串中的所有空白符
 
static String
 difference(String str1, String str2)
          Compares two Strings, and returns the portion where they differ.
比较两个字符串,返回不同的部分。
 
static boolean
 equals(String str1, String str2)
          Compares two Strings, returning true if they are equal.
比较两个字符串是否相等。
 
static boolean
 equalsIgnoreCase(String str1, String str2)
          Compares two Strings, returning true if they are equal ignoring the case.
比较两个字符串是否相等,区分大小写。
 
static String
 escape(String str)
          Deprecated. Use StringEscapeUtils.escapeJava(String) This method will be removed in Commons Lang 3.0
过时了.在Commons Lang 3.0已经没有此方法了
 
static String
 getChomp(String str, String sep)
          Deprecated. Use substringAfterLast(String, String) instead (although this doesn't include the separator) Method will be removed in Commons Lang 3.0.
过时了.在Commons Lang 3.0已经没有此方法了
 
static int
 getLevenshteinDistance(String s, String t)
          Find the Levenshtein distance between two Strings.
计算两个字符串 levenshtein 距离,在计算相似度是用到这个方法
 
static String
 getNestedString(String str, String tag)
          Deprecated. Use the better named substringBetween(String, String). Method will be removed in Commons Lang 3.0.
过时了.在Commons Lang 3.0已经没有此方法了
 
static String
 getNestedString(String str, String open, String close)
          Deprecated. Use the better named substringBetween(String, String, String). Method will be removed in Commons Lang 3.0.
过时了.在Commons Lang 3.0已经没有此方法了
 
static String
 getPrechomp(String str, String sep)
          Deprecated. Use substringBefore(String,String) instead (although this doesn't include the separator). Method will be removed in Commons Lang 3.0.
过时了.在Commons Lang 3.0已经没有此方法了
 
static int
 indexOf(String str, char searchChar)
          Finds the first index within a String, handling null.
返回字符searchChar在字符串str中第一次出现的位置。
如果searchChar没有在str中出现则返回-1,
如果str为null或"",则也返回-1
 
static int
 indexOf(String str, char searchChar, int startPos)
          Finds the first index within a String from a start position, handling null.
返回字符searchChar从startPos开始在字符串str中第一次出现的位置。
如果从startPos开始searchChar没有在str中出现则返回-1,
如果str为null或"",则也返回-1
 
static int
 indexOf(String str, String searchStr)
          Finds the first index within a String, handling null.
返回字符串searchStr在字符串str中第一次出现的位置。
如果str为null或searchStr为null则返回-1,
如果searchStr为"",且str为不为null,则返回0,
如果searchStr不在str中,则返回-1
 
static int
 indexOf(String str, String searchStr, int startPos)
          Finds the first index within a String, handling null.
返回字符串searchStrr从startPos开始在字符串str中第一次出现的位置。
如果从startPos开始searchStrr没有在str中出现则返回-1,
如果str为null或"",则也返回-1
 
static int
 indexOfAny(String str, char[] searchChars)
          Search a String to find the first index of any character in the given set of characters.
找出字符数组searchChars中的字符第一次出现在字符串str中的位置。
如果字符数组中的字符都不在字符串中,则返回-1
如果字符串为null或"",则返回-1
 
static int
 indexOfAny(String str, String searchChars)
          Search a String to find the first index of any character in the given set of characters.
找出字符串searchChars中的字符第一次出现在字符串str中的位置。
如果字符串searchChars中的字符都不在字符串str中,则返回-1
如果searchChars或str为null或为"",则返回-1
 
static int
 indexOfAny(String str, String[] searchStrs)
          Find the first index of any of a set of potential substrings.
找出字符数组searchStrs中的字符串第一次出现在字符串str中的位置。
如果字符串数组searchStrs中的字符都不在字符串str中,则返回-1
如果searchStrs或str为null或为"",则返回-1
 
static int
 indexOfAnyBut(String str, char[] searchChars)
          Search a String to find the first index of any character not in the given set of characters.
找出字符串str中不在字符数组searchChars中的第一个字符的位置。
如果字符串中的所有字符都在字符数组中,则返回-1
如果字符串为null或"",则返回-1
 
static int
 indexOfAnyBut(String str, String searchChars)
          Search a String to find the first index of any character not in the given set of characters.
找出字符串str中不在字符串searchChars中的第一个字符的位置。
如果字符串str中的所有字符都在字符串searchChars中,则返回-1
如果字符串str或searchChars为null或"",则返回-1
 
static int
 indexOfDifference(String str1, String str2)
          Compares two Strings, and returns the index at which the Strings begin to differ.
比较两个字符串,返回第一次不同的位置。
 
static boolean
 isAlpha(String str)
          Checks if the String contains only unicode letters.
判断Str是否由字母组成。
 
static boolean
 isAlphanumeric(String str)
          Checks if the String contains only unicode letters or digits.
判断Str是否由字母或数字组成。
 
static boolean
 isAlphanumericSpace(String str)
          Checks if the String contains only unicode letters, digits or space (' ').
判断Str是否由字母、数字或空格组成。
 
static boolean
 isAlphaSpace(String str)
          Checks if the String contains only unicode letters and space (' ').
【摘自网络】
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值