Package org.miaixz.bus.core.xyz
Class StringKit
java.lang.Object
org.miaixz.bus.core.text.CharsValidator
org.miaixz.bus.core.text.CharsBacker
org.miaixz.bus.core.xyz.StringKit
字符串工具类
- Since:
- Java 17+
- Author:
- Kimi Liu
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String构建新的字符串static StringBuilderbuilder()创建StringBuilder对象static StringBuilderbuilder(int capacity) 创建StringBuilder对象static Stringcapitalize(String text) 按Character.toTitleCase(int)将第一个字符更改为标题大小写.其他字符没有改变static Stringfill(int count, char charVal) 输出指定长度字符static String输出指定长度字符static String将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串static String将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串 字符填充于字符串后static StringfillBefore(String text, char filledChar, int len) 将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串 字符填充于字符串前static Stringformat(CharSequence template, Map<?, ?> map) 格式化文本,使用 {varName} 占位 map = {a: "aValue", b: "bValue"} format("{a} and {b}", map) = aValue and bValuestatic Stringformat(CharSequence template, Map<?, ?> map, boolean ignoreNull) 格式化文本,使用 {varName} 占位 map = {a: "aValue", b: "bValue"} format("{a} and {b}", map) = aValue and bValuestatic StringReadergetReader(CharSequence text) 获得StringReaderstatic StringWriter获得StringWriterstatic boolean检查给定的String是否包含实际的文本。 更具体地说,如果String不是null, 那么这个方法返回true,它的长度大于0,并且至少包含一个非空白字符static String反转字符串 例如:abcd = dcbastatic double计算两个字符串的相似度static String计算两个字符串的相似度百分比static StringstringFast(char[] value) JDK8中,通过String(char[] value, boolean share)这个内部构造创建String对象。 此函数通过传入char[],实现zero-copy的String创建,效率很高。但是要求传入的char[]不可以在其他地方修改。static String解码字节码static String解码字节码static String将对象转为字符串static String将对象转为字符串static StringtoString(ByteBuffer data, Charset charset) 将编码的byteBuffer数据转换为字符串static void给定字符串数组全部做去首尾空格static StringunCapitalize(String text) 取消字符串的大小写,将第一个字符改为小写。其他字符没有改变Methods inherited from class org.miaixz.bus.core.text.CharsBacker
addPrefixIfNot, addSuffixIfNot, appendIfMissing, appendIfMissing, appendIfMissingIgnoreCase, brief, builder, builder, byteLength, center, center, center, cleanBlank, codeLength, commonPrefix, commonSuffix, compare, compareIgnoreCase, compareVersion, concat, contains, contains, containsAll, containsAny, containsAny, containsAnyIgnoreCase, containsBlank, containsIgnoreCase, containsOnly, count, count, cut, defaultIfBlank, defaultIfBlank, defaultIfEmpty, defaultIfEmpty, defaultIfEmpty, defaultIfNull, defaultIfNull, defaultIfNull, emptyIfNull, endWith, endWith, endWith, endWith, endWithAny, endWithAnyIgnoreCase, endWithIgnoreCase, equals, equals, equalsAny, equalsAny, equalsAnyIgnoreCase, equalsCharAt, equalsIgnoreCase, filter, firstNonBlank, firstNonEmpty, firstNonNull, fixLength, format, genGetter, genSetter, getContainsStrIgnoreCase, getContainsString, getGeneralField, hide, indexedFormat, indexOf, indexOf, indexOf, indexOf, indexOf, indexOfIgnoreCase, indexOfIgnoreCase, isCharEquals, isLowerCase, isNumeric, isSubEquals, isSubEquals, isUpperCase, isWrap, isWrap, isWrap, isWrap, join, join, lastIndexOf, lastIndexOfIgnoreCase, lastIndexOfIgnoreCase, left, length, limitByteLength, limitByteLengthUtf8, limitLength, lowerAt, lowerFirst, mid, move, normalize, nullIfEmpty, ordinalIndexOf, padAfter, padAfter, padPre, padPre, prependIfMissing, prependIfMissing, prependIfMissingIgnoreCase, removeAll, removeAll, removeAllLineBreaks, removeAllSuffix, removeAny, removePreAndLowerFirst, removePreAndLowerFirst, removePrefix, removePrefix, removePrefixIgnoreCase, removeSufAndLowerFirst, removeSuffix, removeSuffixIgnoreCase, repeat, repeat, repeatAndJoin, repeatByLength, replace, replace, replace, replace, replace, replaceAt, replaceByCodePoint, replaceByCodePoint, replaceChars, replaceChars, replaceFirst, replaceIgnoreCase, replaceLast, right, split, split, split, split, split, split, split, splitByBlank, splitByBlank, splitByBlankToArray, splitByLength, splitByRegex, splitByRegex, splitByRegexToArray, splitPath, splitPath, splitTo, splitToArray, splitTrim, startWith, startWith, startWith, startWith, startWithAny, startWithAnyIgnoreCase, startWithIgnoreCase, startWithIgnoreEquals, strip, strip, strip, stripIgnoreCase, stripIgnoreCase, sub, subAfter, subAfter, subBefore, subBefore, subBetween, subBetween, subBetweenAll, subBetweenAll, subByCodePoint, subByLength, subPre, subPreGbk, subPreGbk, subSuf, subSufByLength, swapCase, toCamelCase, toCamelCase, toChars, toStringOrEmpty, toStringOrNull, toSymbolCase, totalLength, toUnderlineCase, trim, trim, trim, trimFunc, trimPrefix, trimSuffix, trimToEmpty, trimToNull, unWrap, unWrap, unWrap, upperAt, upperFirst, upperFirstAndAddPre, wrap, wrap, wrap, wrapAll, wrapAllIfMissing, wrapAllWithPair, wrapAllWithPairIfMissing, wrapIfMissingMethods inherited from class org.miaixz.bus.core.text.CharsValidator
hasBlank, hasEmpty, hasEmpty, isAllBlank, isAllCharMatch, isAllEmpty, isAllEmpty, isAllNotBlank, isAllNotEmpty, isBlank, isBlankOrUndefined, isEmpty, isEmptyOrUndefined, isNotBlank, isNotEmpty, isNullOrUndefined
-
Constructor Details
-
StringKit
public StringKit()
-
-
Method Details
-
trim
给定字符串数组全部做去首尾空格- Parameters:
args- 字符串数组
-
toString
将对象转为字符串1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
- Parameters:
obj- 对象- Returns:
- 字符串
-
toString
将对象转为字符串1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、char[]会直接构造String 3、对象数组会调用Arrays.toString方法- Parameters:
obj- 对象charset- 字符集- Returns:
- 字符串
-
toString
解码字节码- Parameters:
data- 字符串charset- 字符集,如果此字段为空,则解码的结果取决于平台- Returns:
- 解码后的字符串
-
toString
解码字节码- Parameters:
data- 字符串charset- 字符集,如果此字段为空,则解码的结果取决于平台- Returns:
- 解码后的字符串
-
toString
将编码的byteBuffer数据转换为字符串- Parameters:
data- 数据charset- 字符集,如果为空使用当前系统字符集- Returns:
- 字符串
-
stringFast
JDK8中,通过String(char[] value, boolean share)这个内部构造创建String对象。 此函数通过传入char[],实现zero-copy的String创建,效率很高。但是要求传入的char[]不可以在其他地方修改。- Parameters:
value- char[]值,注意这个数组不可修改!!- Returns:
- String
-
builder
创建StringBuilder对象- Returns:
- StringBuilder对象
-
builder
创建StringBuilder对象- Parameters:
capacity- 初始大小- Returns:
- StringBuilder对象
-
getReader
获得StringReader- Parameters:
text- 字符串- Returns:
- StringReader
-
getWriter
获得StringWriter- Returns:
- StringWriter
-
reverse
反转字符串 例如:abcd = dcba- Parameters:
text- 被反转的字符串- Returns:
- 反转后的字符串
-
fillBefore
将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串 字符填充于字符串前- Parameters:
text- 被填充的字符串filledChar- 填充的字符len- 填充长度- Returns:
- 填充后的字符串
-
fillAfter
将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串 字符填充于字符串后- Parameters:
text- 被填充的字符串filledChar- 填充的字符len- 填充长度- Returns:
- 填充后的字符串
-
fill
将已有字符串填充为规定长度,如果已有字符串超过这个长度则返回这个字符串- Parameters:
text- 被填充的字符串filledChar- 填充的字符len- 填充长度isPre- 是否填充在前- Returns:
- 填充后的字符串
-
fill
输出指定长度字符- Parameters:
count- 长度charVal- 字符- Returns:
- 填充后的字符串
-
fill
输出指定长度字符- Parameters:
count- 长度strVal- 字符- Returns:
- 填充后的字符串
-
similar
计算两个字符串的相似度- Parameters:
str1- 字符串1str2- 字符串2- Returns:
- 相似度
-
similar
计算两个字符串的相似度百分比- Parameters:
str1- 字符串1str2- 字符串2scale- 相似度- Returns:
- 相似度百分比
-
format
格式化文本,使用 {varName} 占位 map = {a: "aValue", b: "bValue"} format("{a} and {b}", map) = aValue and bValue- Parameters:
template- 文本模板,被替换的部分用 {data} 表示map- 参数值对- Returns:
- 格式化后的文本
-
format
格式化文本,使用 {varName} 占位 map = {a: "aValue", b: "bValue"} format("{a} and {b}", map) = aValue and bValue- Parameters:
template- 文本模板,被替换的部分用 {data} 表示map- 参数值对ignoreNull- 是否忽略null值,忽略则null值对应的变量不被替换,否则替换为""- Returns:
- 格式化后的文本
-
hasText
检查给定的String是否包含实际的文本。 更具体地说,如果String不是null, 那么这个方法返回true,它的长度大于0,并且至少包含一个非空白字符- Parameters:
text- 要检查的String(可能是null)- Returns:
- 如果
String不是null,那么它的长度大于0,并且不包含空格
-
build
构建新的字符串- Parameters:
original- 原始对象middle- 中间隐藏信息prefixLength- 前边信息长度- Returns:
- 构建后的新字符串
-
capitalize
按Character.toTitleCase(int)将第一个字符更改为标题大小写.其他字符没有改变StringKit.capitalize(null) = null StringKit.capitalize("") = "" StringKit.capitalize("cat") = "Cat" StringKit.capitalize("cAt") = "CAt" StringKit.capitalize("'cat'") = "'cat'"- Parameters:
text- 要大写的字符串可以为空- Returns:
- 大写字符串,
null如果输入为空字符串
-
unCapitalize
取消字符串的大小写,将第一个字符改为小写。其他字符没有改变StringKit.uncapitalize(null) = null StringKit.uncapitalize("") = "" StringKit.uncapitalize("cat") = "cat" StringKit.uncapitalize("Cat") = "cat" StringKit.uncapitalize("CAT") = "cAT"- Parameters:
text- 要取消大写的字符串可以为空- Returns:
- 未大写的字符串,
null如果输入为空字符串
-