org.apache.commons.lang
Class StringUtils
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 $
static String | EMPTY |
static int | INDEX_NOT_FOUND |
Constructor Summary 构造方法摘要 | |
StringUtils () |
|
Method Summary 方法摘要 | |
static String | abbreviate (String str, int maxWidth) 取得字符串的缩写,str: 处理的字符串,maxWidth: 宽度,从第一个字符开始[1,maxWidth), 类似于substring(), 返回一个新的字符串,它是此字符串的一个子字符串。 |
static String | abbreviate (String str, int offset, int maxWidth) 取得字符串的缩写,str: 处理的字符串,maxWidth: 宽度,从第offset 个字符开始[offset,axWidth), 类似于substring(), 返回一个新的字符串,它是此字符串的一个子字符串。 |
static String | capitalise (String str) 过时了. 用 capitalize(String) ,在Commons Lang 3.0 已经没有此方法了。 |
static String | capitaliseAllWords (String str) 过时了. 在Commons Lang 3.0 已经没有此方法了。 |
static String | capitalize (String str) 将str 手写字母大写,用于名称、头衔等 |
static String | center (String str, int size) 产生一个字符串返回,该字符串长度等于 size , str 位于新串的中心,其他位置补空格。 |
static String | center (String str, int size, char padChar) 产生一个字符串返回,该字符串长度等于 size , str 位于新串的中心,其他位置补字符 padChar 。 |
static String | center (String str, int size, String padStr) 产生一个字符串返回,该字符串长度等于 size , str 位于新串的中心,其他位置补字符串 padStr 。 |
static String | chomp (String str) 以单个词为单位的反转 str=”I am yuanyuan !”; chomp(str)=”! yuanyuan an I”; |
static String | chomp (String str, String separator) 以单个词为单位的反转,从 separator 开始 str=”I am yuanyuan !”; chomp(str ,”!”)=” yuanyuan an I !”; |
static String | chompLast (String str) 过时了. 在Commons Lang 3.0 已经没有此方法了 |
static String | chompLast (String str, String sep) 过时了. 在Commons Lang 3.0 已经没有此方法了 |
static String | chop (String str) 去掉字符串 str 的最后一个字符。如果字符串以 "\r\n" 结尾,则去掉它们。 |
static String | chopNewline (String str) 过时了. 在Commons Lang 3.0 已经没有此方法了 |
static String | clean (String str) 过时了. 在Commons Lang 3.0 已经没有此方法了 |
static String | concatenate (Object [] array) 过时了. 在Commons Lang 3.0 已经没有此方法了 |
static boolean | contains (String str, char searchChar) 当此字符串包含指定的字符 searchChar 值序列时,返回 true ;处理 null 。 |
static boolean | contains (String str, String searchStr) 当此字符串包含指定的字符串 searchStr 值序列时,返回 true ;处理 null 。 |
static boolean | containsIgnoreCase (String str, String searchStr) 当此字符串包含指定的字符串 searchStr 值序列时,忽略大小写,返回 true ;处理 null 。 |
static boolean | containsNone (String str, char[] invalidChars) 判断是否字符串 str 不包含字符数组 invalidChars 中的字符 , 如果含有则返回 |