public class Strings extends Object
| 构造器和说明 |
|---|
Strings() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
capitalize(String name)
将首字母大写,其它不变
|
static String |
compactSize(long num)
转换为紧凑格式的字节数表示
最多保留两位小数
|
static boolean |
equals(String val1,
String val2)
比较两个字符串是否相等
|
static String |
escapeHTML(String input)
编码HTML标记为浏览器可显示格式.
|
static String |
escapeXML(String xml)
编码XML标记.
|
static int |
gbStrLen(String str)
取带汉字字串的length 将带字符串按Byte位长度取子字符串 防止带汉字的字符串长度取错
|
static String |
gbsubstr(String src,
int beginIndex,
int endIndex)
处理汉字字串的substr 将带字符串按Byte位长度取子字符串 防止带汉字的字符串长度取错 防止出现Exception 防止出现半个汉字
|
static String |
gbsubstr(String src,
int beginIndex,
int endIndex,
boolean ifAdd)
处理汉字字串的substr.
|
static String |
getDefaultCharacterEncoding()
获取平台缺省的字符集
|
static byte[] |
hexToBytes(String hex)
将16进制表示的字符串转换为字节数组.
|
static boolean |
isEmpty(String str)
判断是否是空字符串 null和"" 都返回 true
|
static String |
join(List<?> list,
String symbol)
把string array or list用给定的符号symbol连接成一个字符串
null or empty item will be ignored.
|
static String |
lFillStr(String src,
char ch,
int len)
左对齐填充定长字符串.
|
static String |
nullable(Object obj)
将对象转换为字符串.
|
static String |
omit(String s,
int maxlength)
截断字符串,当字符长度超过指定长度时截断,并将最后3位用“...”替换(长度按字节计算)
|
static String |
omit(String s,
String encoding,
int maxlength)
截断字符串,当字符长度超过指定长度时截断,并将最后3位用“...”替换(长度按字节计算)
|
static String |
replace(String input,
String matchString,
String newString)
将源字符串中所有匹配的字符串替换为提供的新字符串(不使用正则表达式).
|
static String |
replaceVar(String value,
Map<String,?> staticProp)
用提供的属性替换字符串中的${NAME}变量
|
static String |
replicateStr(char ch,
int len)
用单个字符重复填充一定长度的字符串
|
static String |
rFillStr(String src,
char ch,
int len)
右对齐填充定长字符串.
|
static String |
rFillStr(String src,
char ch,
int len,
boolean gb)
右对齐填充定长字符串.
|
static List<String> |
split(String input)
按空白字符(空格)或逗号分隔字符串.
|
static List<String> |
split(String s,
char delimiter)
以单个字符为分隔符分割字符串,并截去前后空格.
|
static List<String> |
split(String s,
char delimiter,
boolean trim)
以单个字符为分隔符分割字符串(可选是否截断空格).
|
static List<String> |
split(String input,
String sep)
使用指定的正则表达式分隔字符串.
|
static String[] |
splitLines(String str)
将多行文本分割为字符串数组(每行一组).
|
static String |
substr(String src,
int beginIndex,
int endIndex)
将带字符串按Byte位长度取子字符串.
|
static String |
toHex(byte[] hash)
将字节转换为16进制字符串显示.
|
static String |
toString(Object obj,
String defaultValue)
将对象转换为字符串.
|
static String |
trimPunct(String str)
删除所有的标点符号
|
static String |
unCapitalize(String name)
将首字母小写,其它不变
|
static String |
unescapeXML(String input)
反编码XML内容字符串.
|
public static boolean isEmpty(String str)
str - 判断的字符串public static String toString(Object obj, String defaultValue)
obj - 待转换对象defaultValue - 缺省值public static String nullable(Object obj)
obj - 待转换对象public static String join(List<?> list, String symbol)
null or empty item will be ignored.
list - 需要处理的列表symbol - 链接的符号public static String[] splitLines(String str)
分行符可以是:换行\n(Unix格式),或回车加换行\r\n(Dos格式).
str - 待分割文本字符串public static List<String> split(String s, char delimiter, boolean trim)
不使用正则表达式,提高性能。
s - 待分割字符串delimiter - 字符分融符trim - 是否截去前后空格public static List<String> split(String s, char delimiter)
split(s, delimiter, true)的快捷方式.
| 源串 | 结果 |
| a, , ,, b | [a,,,,b] |
| a,b c ,d | [a,b c,d] |
s - 待分割字符串delimiter - 分融符public static List<String> split(String input)
| 源串 | 结果 |
| a,,,,b | [a, b] |
| a,b c,d | [a, b, c, d] |
input - 源串public static List<String> split(String input, String sep)
本方法的返回结果中不包括零长字符串(这是与String.split方法的不同之处)
input - 源串sep - 正则表达式public static final String replace(String input, String matchString, String newString)
input - 源字符串matchString - 匹配字符串newString - 新字符串public static final String escapeXML(String xml)
将字符串中的XML关键字符用XML标记替换.使其可置于xml文档中.
xml - 待编码字符串.public static final String unescapeXML(String input)
input - 待反编码字符串Strings#escapeForXML(String)public static final String escapeHTML(String input)
将字符串中的HTML关键字符用HTML标记替换 .将换行符转为<br>
input - 待编码字符串.escapeXML(String).public static String replaceVar(String value, Map<String,?> staticProp)
value - 待替换的字符串staticProp - 静态属性对照表public static final String toHex(byte[] hash)
hash - 待转换字节数组public static final byte[] hexToBytes(String hex)
hex - 待转换16进制表示的字符串public static final String compactSize(long num)
最多保留两位小数
number - 字节数(单位:B)public static String getDefaultCharacterEncoding()
public static String substr(String src, int beginIndex, int endIndex)
String - src 源字符串int - beginIndex 起始位置,0为第一位int - endIndex 终止位置,1为第一位public static String gbsubstr(String src, int beginIndex, int endIndex, boolean ifAdd)
String - src 源字符串int - beginIndex 起始位置,0为第一位int - endIndex 终止位置,1为第一位boolean - ifAdd
public static String gbsubstr(String src, int beginIndex, int endIndex)
String - src 源字符串int - beginIndex 起始位置,0为第一位int - endIndex 终止位置,1为第一位 如果最后是半个汉字,返回长度减一public static int gbStrLen(String str)
String - str 源字符串public static String replicateStr(char ch, int len)
ch - 用于填充的字符len - 被填充的字符串长度public static String lFillStr(String src, char ch, int len)
src - 源字符串ch - 用于填充的字符len - 新字符串总长度public static String rFillStr(String src, char ch, int len)
src - ch - len - public static String rFillStr(String src, char ch, int len, boolean gb)
src - 源字符串ch - 用于填充的字符len - 新字符串长度gb - 源字符串是否包含有中文public static String omit(String s, int maxlength)
s - 源字符串maxlength - 指定最大长度public static String omit(String s, String encoding, int maxlength)
s - 源字符串encoding - 编码maxlength - 指定最大长度Copyright © 2016 l88. All rights reserved.