public class StringHelper
extends java.lang.Object
限定符和类型 | 字段和说明 |
---|---|
static java.lang.String |
EMPTY
空字符串
|
构造器和说明 |
---|
StringHelper() |
限定符和类型 | 方法和说明 |
---|---|
static java.lang.String |
Base64Encode(java.lang.String str)
转为Base64
|
static java.lang.String |
bytesToHexString(byte[] src)
二进制专为字符串
|
static java.lang.String |
encryptMd5(java.lang.String str)
MD5解密
|
static java.lang.String |
formatByte(long size)
返回对应的总数
|
static boolean |
isBlank(java.lang.String str)
Checks if a String is whitespace, empty ("") or null.
|
static boolean |
isEmpty(java.lang.String str)
Checks if a String is empty ("") or null.
|
static boolean |
isLetter(java.lang.String txt,
int preLength)
是否为字母
|
static boolean |
isNotBlank(java.lang.String str)
Checks if a String is not empty (""), not null and not whitespace only.
|
static boolean |
isNotEmpty(java.lang.String str)
Checks if a String is not empty ("") and not null.
|
static int |
matchInt(java.lang.String input,
java.lang.String regex)
获取匹配正则整数
|
static java.lang.String |
matchString(java.lang.String input,
java.lang.String regex)
获取匹配正则字符串
String sms = "【完美故事】09828344(完美故事验证码)或点击 b.mgushi.com/s/09828344";
String code = StringHelper.matchString(sms, "[^0-9]*([0-9]{6})[^0-9]*");
L.i("code: %s", code);
|
static java.util.ArrayList<java.lang.String> |
matchStrings(java.lang.String input,
java.lang.String regex)
获取匹配正则字符串
|
static java.lang.String |
md5(byte[] bytes)
MD5
|
static java.lang.String |
md5(java.lang.String s)
MD5
|
static float |
parseFloat(java.lang.String txt)
转换成小数
|
static int |
parserInt(java.lang.String txt)
转换成整形
|
static int |
parserInt(java.lang.String txt,
int radix)
转换成整形
|
static long |
parserLong(java.lang.String txt)
转换成长整数
|
static java.lang.String |
removeSuffix(java.lang.String fileName)
删除文件后缀
|
static java.lang.String |
timeStampString()
获取时间戳字符串
|
static java.lang.String |
trim(java.lang.String str)
Removes control characters (char <= 32) from both ends of this String,
handling
null by returning null . |
static java.lang.String |
trimToEmpty(java.lang.String str)
Removes control characters (char <= 32) from both ends of this String
returning an empty String ("") if the String is empty ("") after the trim
or if it is
null . |
static java.lang.String |
trimToNull(java.lang.String str)
Removes control characters (char <= 32) from both ends of this String
returning
null if the String is empty ("") after the trim or
if it is null . |
static java.util.HashMap<java.lang.String,java.lang.String> |
urlQuery(java.lang.String query)
分割链接参数
|
static java.lang.String |
uuid()
获取唯一标识符
|
public static final java.lang.String EMPTY
public static boolean isEmpty(java.lang.String str)
Checks if a String is empty ("") or null.
StringHelper.isEmpty(null) = true StringHelper.isEmpty("") = true StringHelper.isEmpty(" ") = false StringHelper.isEmpty("bob") = false StringHelper.isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0. It no longer trims the String. That functionality is available in isBlank().
str
- the String to check, may be nulltrue
if the String is empty or nullpublic static boolean isNotEmpty(java.lang.String str)
Checks if a String is not empty ("") and not null.
StringHelper.isNotEmpty(null) = false StringHelper.isNotEmpty("") = false StringHelper.isNotEmpty(" ") = true StringHelper.isNotEmpty("bob") = true StringHelper.isNotEmpty(" bob ") = true
str
- the String to check, may be nulltrue
if the String is not empty and not nullpublic static boolean isBlank(java.lang.String str)
Checks if a String is whitespace, empty ("") or null.
StringHelper.isBlank(null) = true StringHelper.isBlank("") = true StringHelper.isBlank(" ") = true StringHelper.isBlank("bob") = false StringHelper.isBlank(" bob ") = false
str
- the String to check, may be nulltrue
if the String is null, empty or whitespacepublic static boolean isNotBlank(java.lang.String str)
Checks if a String is not empty (""), not null and not whitespace only.
StringHelper.isNotBlank(null) = false StringHelper.isNotBlank("") = false StringHelper.isNotBlank(" ") = false StringHelper.isNotBlank("bob") = true StringHelper.isNotBlank(" bob ") = true
str
- the String to check, may be nulltrue
if the String is
not empty and not null and not whitespacepublic static java.lang.String trim(java.lang.String str)
Removes control characters (char <= 32) from both ends of this String,
handling null
by returning null
.
The String is trimmed using String.trim()
. Trim removes start and
end characters <= 32. To strip whitespace use #strip(String)
.
To trim your choice of characters, use the #strip(String, String)
methods.
StringHelper.trim(null) = null StringHelper.trim("") = "" StringHelper.trim(" ") = "" StringHelper.trim("abc") = "abc" StringHelper.trim(" abc ") = "abc"
str
- the String to be trimmed, may be nullnull
if null String inputpublic static java.lang.String trimToNull(java.lang.String str)
Removes control characters (char <= 32) from both ends of this String
returning null
if the String is empty ("") after the trim or
if it is null
.
The String is trimmed using String.trim()
. Trim removes start and
end characters <= 32. To strip whitespace use
#stripToNull(String)
.
StringHelper.trimToNull(null) = null StringHelper.trimToNull("") = null StringHelper.trimToNull(" ") = null StringHelper.trimToNull("abc") = "abc" StringHelper.trimToNull(" abc ") = "abc"
str
- the String to be trimmed, may be nullnull
if only chars <= 32,
empty or null String inputpublic static java.lang.String trimToEmpty(java.lang.String str)
Removes control characters (char <= 32) from both ends of this String
returning an empty String ("") if the String is empty ("") after the trim
or if it is null
.
The String is trimmed using String.trim()
. Trim removes start and
end characters <= 32. To strip whitespace use
#stripToEmpty(String)
.
StringHelper.trimToEmpty(null) = "" StringHelper.trimToEmpty("") = "" StringHelper.trimToEmpty(" ") = "" StringHelper.trimToEmpty("abc") = "abc" StringHelper.trimToEmpty(" abc ") = "abc"
str
- the String to be trimmed, may be nullnull
inputpublic static java.lang.String md5(java.lang.String s)
s
- public static java.lang.String md5(byte[] bytes)
bytes
- public static java.lang.String encryptMd5(java.lang.String str)
str
- public static java.lang.String Base64Encode(java.lang.String str)
str
- public static java.lang.String uuid()
public static java.util.HashMap<java.lang.String,java.lang.String> urlQuery(java.lang.String query)
query
- public static java.lang.String timeStampString()
public static java.lang.String formatByte(long size)
size
- public static boolean isLetter(java.lang.String txt, int preLength)
txt
- 输入字符串preLength
- 字符串前面是否为字母 设置为0将查询整个字符串public static int parserInt(java.lang.String txt)
txt
- public static int parserInt(java.lang.String txt, int radix)
txt
- (FF)radix
- 进制public static float parseFloat(java.lang.String txt)
txt
- 输入字符串public static long parserLong(java.lang.String txt)
txt
- 输入字符串public static java.lang.String bytesToHexString(byte[] src)
src
- public static int matchInt(java.lang.String input, java.lang.String regex)
input
- regex
- public static java.lang.String matchString(java.lang.String input, java.lang.String regex)
input
- regex
- public static java.util.ArrayList<java.lang.String> matchStrings(java.lang.String input, java.lang.String regex)
input
- regex
- public static java.lang.String removeSuffix(java.lang.String fileName)
fileName
-