JAVA StringUtils工具类
<strong><strong><strong><br /><br /><br /></strong></strong></strong>
org.apache.commons.lang
Class StringUtils
java.lang.Object
<strong><strong><strong></strong></strong></strong>
<strong>org.apache.commons.lang.StringUtils</strong>
public class <strong>StringUtils</strong>extends Object
Operations onString
that arenull
safe.
- IsEmpty/IsBlank- checks if a String contains text
- Trim/Strip- removes leading and trailing whitespace
- Equals- compares two strings null-safe
- startsWith- check if a String starts with a prefix null-safe
- endsWith- check if a String ends with a suffix null-safe
- IndexOf/LastIndexOf/Contains- null-safe index-of checks
- IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut- index-of any of a set of Strings
- ContainsOnly/ContainsNone/ContainsAny- does String contains only/none/any of these characters
- Substring/Left/Right/Mid- null-safe substring extractions
- SubstringBefore/SubstringAfter/SubstringBetween- substring extraction relative to other strings
- Split/Join- splits a String into an array of substrings and vice versa
- Remove/Delete- removes part of a String
- Replace/Overlay- Searches a String and replaces one String with another
- Chomp/Chop- removes the last part of a String
- LeftPad/RightPad/Center/Repeat- pads a String
- UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize- changes the case of a String
- CountMatches- counts the number of occurrences of one String in another
- IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable- checks the characters in a String
- DefaultString- protects against a null input String
- Reverse/ReverseDelimited- reverses a String
- Abbreviate- abbreviates a string using ellipsis
- Difference- compares Strings and reports on their differences
- LevensteinDistance- the number of changes needed to change one String into another
TheStringUtils
class defines certain words related to String handling.
- null -
null
- empty - a zero-length string (
""
) - space - the space character (
' '
, char 32) - whitespace - the characters defined by
Character.isWhitespace(char)
- trim - the characters <= 32 as in
String.trim()
StringUtils
handlesnull
input Strings quietly. That is to say that anull
input will returnnull
. Where aboolean
orint
is being returned details vary by method.
A side effect of thenull
handling is that aNullPointerException
should be considered a bug inStringUtils
(except for deprecated methods).
Methods in this class give sample code to explain their operation. The symbol*
is used to indicate any input includingnull
.
<strong><strong><strong><br /><br />翻译:Google<br /><br /></strong></strong></strong>
org.apache.commons.lang
类StringUtils
<span>java.lang.Object
<strong><strong><strong></strong></strong></strong>
<strong>org.apache.commons.lang.StringUtils</strong>
<span>公共类<strong>StringUtils</strong><span>扩展<span>Object
这样做的操作String
是null
安全的。
- IsEmpty / IsBlank- 检查一个String是否包含文本
- 修剪/去除- 去除前导和尾随的空白
- 等于- 比较两个字符串无效
- startsWith- 检查一个字符串是否以一个前缀为null开头
- endsWith- 检查一个String是否以一个后缀为null结尾
- IndexOf / LastIndexOf / Contains- 无效索引的检查
- IndexOfAny / LastIndexOfAny / IndexOfAnyBut / LastIndexOfAnyBut- 索引 - 任何一组字符串
- ContainsOnly / ContainsNone / ContainsAny- 是String只包含/ none /任何这些字符
- 子字符串/左/右/中- 零安全子串提取
- SubstringBefore / SubstringAfter / SubstringBetween- 相对于其他字符串的子字符串提取
- 拆分/连接- 将一个字符串拆分为一个子字符串数组,反之亦然
- 删除/删除- 删除部分字符串
- 替换/覆盖- 搜索一个字符串并用另一个替换一个字符串
- Chomp / Chop- 删除字符串的最后部分
- 左键盘/右键盘/中心/重复-填充字符串
- UpperCase / LowerCase / SwapCase / Capitalize / Uncapitalize- 更改字符串的大小写
- CountMatches- 统计另一个字符串的出现次数
- IsAlpha / IsNumeric / IsWhitespace / IsAsciiPrintable- 检查字符串中的字符
- DefaultString- 防止空输入字符串
- Reverse / ReverseDelimited- 反转字符串
- 缩写- 使用省略号缩写字符串
- 差异- 比较字符串和报告差异
- LevensteinDistance- 将一个字符串更改为另一个字符串所需的更改次数
在StringUtils
类定义与字符串处理某些词。
- 空值 -
null
- 空 - 一个零长度的字符串(
""
) - 空格 - 空格字符(
' '
char 32) - 空格 - 由...定义的字符
Character.isWhitespace(char)
- 修剪 - 在<= 32的字符
String.trim()
StringUtils
null
静静地处理输入字符串。这就是说,一个null
输入将返回null
。在哪里boolean
或int
正在退货的细节因方法而异。
处理的一个副作用null
是aNullPointerException
应该被认为是一个错误StringUtils
(除了被弃用的方法)。
这个类中的方法给出了示例代码来解释它们的操作。该符号*
用于指示包括的任何输入null
。
<strong><strong><strong> <br />检查字符串是否为空</strong></strong></strong>
isNotEmpty 将空格也作为参数,isNotBlank 则排除空格参数
<strong>isNoneEmpty 可添加多个参数<strong>将空格也作为参数 , <strong>isNoneBlank 可添加多个参数,排除空格参数<br /><br /><br />去掉字符串前后的空白<br /><strong>Trim/Strip</strong><br /><br />比较两个字符串是否相等<br /><strong>Equals</strong> <br /><br />检查字符串是否以null前缀为开头<br /><strong>startsWith</strong> <br /><br />检查字符串是否以null后缀为结尾<br /><br />检查字符串是否包含一个特定的字符<br /><strong>IndexOf / LastIndexOf / Contains</strong><br /><br /><br /></strong></strong></strong>
<strong><strong><strong><br /><br /></strong></strong></strong>