public class StringUtils extends Object
构造器和说明 |
---|
StringUtils() |
限定符和类型 | 方法和说明 |
---|---|
static String |
afterIndex(String str,
String index) |
static String |
afterLastIndex(String str,
String index) |
static String |
applyRelativePath(String path,
String relativePath)
Apply the given relative path to the given path, assuming standard Java folder separation (i.e. "/" separators).
|
static boolean |
areNotBlank(CharSequence... values)
Checks if all the String are empty (""), null or whitespace(e.g. " ", "\t", "\n").
|
static boolean |
areNotEmpty(CharSequence... values)
Checks if all the String are null or empty ("").
|
static String |
beforeIndex(String str,
String index) |
static String |
beforeLastIndex(String str,
String index) |
static String |
changeEncode(String str,
String newCharset)
字符串编码转换
|
static boolean |
charEqualIgnoreCase(char c1,
char c2)
判断两个字符是否相等(忽略大小写)。
|
static String |
cleanPath(String path)
Normalize the path by suppressing sequences like "path/.." and
inner simple dots.
|
static boolean |
containsIgnoreCase(String subject,
String search)
Returns true if and only if this string contains the specified
sequence of char values.
|
static int |
countOccurrencesOf(String str,
String sub)
Count the occurrences of the substring in string s.
|
static String |
decideCharSet(String charSet) |
static boolean |
equals(String str1,
String str2)
判断两个字符串是否相等,包含空字符串的情况
|
static byte[] |
getBytes(String str)
重新定义了String.getBytes()。
|
static byte[] |
getBytes(String str,
String charSet)
String.getBytes(),将CheckedException转换成了RuntimeException。
|
static String |
getFilenameExtension(String path)
从路径(url或者目录都可以)中获取文件后缀(比如 txt)
Extract the filename extension from the given path, e.g. |
static String |
getFilenameFromPath(String path)
从路径(url或者目录都可以)中获取文件名称(带后缀,形如 abc.txt)
Extract the filename from the given path, e.g. |
static String |
getFilenameWithoutExtension(String path)
从路径(url或者目录都可以)中获取文件名称(不带后缀,形如 abc)
Extract the filename without it's extension from the given path, e.g. |
static String |
getJvmEncoding()
当前环境的默认编码(即file.encoding)
|
static int |
indexIgnoreCase(String subject,
String search)
Case in-sensitive find of the first index within a String.
|
static int |
indexIgnoreCase(String subject,
String search,
int fromIndex)
|
static boolean |
isBlank(CharSequence str)
Checks if a String is empty (""), null or whitespace(e.g. " ", "\t", "\n").
|
static boolean |
isEmpty(CharSequence str)
Checks if a String is null or empty ("").
|
static boolean |
isNotBlank(CharSequence str)
Checks if a String is empty (""), null or whitespace(e.g. " ", "\t", "\n").
|
static boolean |
isNotEmpty(CharSequence str)
Checks if a String is null or empty ("").
|
static boolean |
isNullOrEmpty(CharSequence str)
Checks if a String is null or empty ("").
|
static int |
lastIndexIgnoreCase(String subject,
String search)
Case in-sensitive find of the last index within a String.
|
static int |
lastIndexIgnoreCase(String subject,
String search,
int fromIndex)
|
static String |
middleOfIndex(String str,
String index1,
String index2) |
static String |
newString(byte[] bytes) |
static String |
newString(byte[] bytes,
String charSet) |
static String |
nullToEmpty(String str)
将null转换成空字符串""
|
static String |
replace(String inString,
String oldPattern,
String newPattern)
Replace all occurences of a substring within a string with another string.
|
static String |
replaceParams(Object msg,
Object... objs)
用objs[]的值去替换字符串s中的{}符号
|
static String |
replaceParams(String s,
String... objs) |
static String |
simpleHtmlEscape(String str)
转换html里面的5个特殊字符:
&, <, >, ', and " , |
static String |
simpleHtmlUnEscape(String str) |
static String |
stripFilenameFromPath(String path)
从路径(url或者目录都可以)中剥去文件名,获得文件所在的目录。
|
static String |
stripIndex(String str,
String index) |
static Charset |
toCharSet(String charSet) |
public static boolean isEmpty(CharSequence str)
StringUtils.isEmpty(null) = true StringUtils.isEmpty("") = true StringUtils.isEmpty(" ") = false StringUtils.isEmpty("12345") = false StringUtils.isEmpty(" 12345 ") = false
public static boolean isNullOrEmpty(CharSequence str)
the same as isEmpty(CharSequence)
public static boolean isNotEmpty(CharSequence str)
public static boolean areNotEmpty(CharSequence... values)
public static boolean isBlank(CharSequence str)
StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ") = true StringUtils.isBlank("12345") = false StringUtils.isBlank(" 12345 ") = false
public static boolean isNotBlank(CharSequence str)
public static boolean areNotBlank(CharSequence... values)
public static String getJvmEncoding()
public static byte[] getBytes(String str)
且将CheckedException转换成了RuntimeException。
str
- 原字符串public static byte[] getBytes(String str, String charSet)
默认用UTF-8编码,以便去除与平台的相关性。
str
- 原字符串public static String newString(byte[] bytes)
public static String changeEncode(String str, String newCharset)
newCharset
- 新编码,例如UTF-8public static String replace(String inString, String oldPattern, String newPattern)
[非正则表达式,区别于String.replace()方法]
inString
- String to examineoldPattern
- String to replacenewPattern
- String to insertpublic static String replaceParams(String s, String... objs)
#replaceParams(String, Object...)
public static String simpleHtmlEscape(String str)
&, <, >, ', and "
,public static int countOccurrencesOf(String str, String sub)
str
- string to search in. Return 0 if this is null.sub
- string to search for. Return 0 if this is null.public static boolean charEqualIgnoreCase(char c1, char c2)
public static boolean containsIgnoreCase(String subject, String search)
subject
- the String to check, may be nullsearch
- the String to search forsearch
, false otherwisepublic static int indexIgnoreCase(String subject, String search)
Case in-sensitive find of the first index within a String.
A null
String will return -1
.
A negative start position is treated as zero.
An empty ("") search String always matches.
A start position greater than the string length only matches
an empty search String.
StringUtils.indexIgnoreCase(null, *) = -1 StringUtils.indexIgnoreCase(*, null) = -1 StringUtils.indexIgnoreCase("", "") = 0 StringUtils.indexIgnoreCase("aabaabaa", "a") = 0 StringUtils.indexIgnoreCase("aabaabaa", "b") = 2 StringUtils.indexIgnoreCase("aabaabaa", "ab") = 1
subject
- the String to check, may be nullsearch
- the String to find, may be nullnull
string inputpublic static int lastIndexIgnoreCase(String subject, String search)
Case in-sensitive find of the last index within a String.
A null
String will return -1
.
A negative start position returns -1
.
An empty ("") search String always matches unless the start position is negative.
A start position greater than the string length searches the whole string.
StringUtils.lastIndexOfIgnoreCase(null, *) = -1 StringUtils.lastIndexOfIgnoreCase(*, null) = -1 StringUtils.lastIndexOfIgnoreCase("aabaabaa", "A") = 7 StringUtils.lastIndexOfIgnoreCase("aabaabaa", "B") = 5 StringUtils.lastIndexOfIgnoreCase("aabaabaa", "AB") = 4
subject
- the String to check, may be nullsearch
- the String to find, may be nullnull
string inputpublic static int lastIndexIgnoreCase(String subject, String search, int fromIndex)
public static String getFilenameFromPath(String path)
path
- the file path (may be null
)null
if nonepublic static String stripFilenameFromPath(String path)
path
- the file path (may be null
)null
if nonepublic static String getFilenameWithoutExtension(String path)
path
- the file path (may be null
)null
if nonepublic static String getFilenameExtension(String path)
path
- the file path (may be null
)null
if nonepublic static String applyRelativePath(String path, String relativePath)
path
- the path to start from (usually a full file path)relativePath
- the relative path to apply (relative to the full file path above)public static String cleanPath(String path)
The result is convenient for path comparison. For other uses, notice that Windows separators ("\") are replaced by simple slashes.
path
- the original pathCopyright © 2018 jretty-org. All rights reserved.