类 TextUtils
java.lang.Object
org.beetl.core.util.TextUtils
文本工具类
修改自
android.text.TextUtil-
嵌套类概要
嵌套类修饰符和类型类说明static interfaceAn interface for splitting strings according to rules that are opaque to the user of this interface.static enum -
方法概要
修饰符和类型方法说明static @NotNull CharSequenceconcat(CharSequence... text) 拼接若干个字符序列static booleandelimitedStringContains(String delimitedString, char delimiter, String item) 判断带分隔符的列表是否包含特定项(不分配内存)static StringemptyIfNull(@Nullable String str) 如果给定字符串为null,则返回 ""static booleanequals(CharSequence a, CharSequence b) Returns true if a and b are equal, including if they are both null.static @NotNull StringfirstNotEmpty(@Nullable String a, @NotNull String b) 如果第一个字符串不为Empty,则返回第一个字符串,返回第二个字符串的非null形式(为null则返回"")static voidgetChars(CharSequence s, int start, int end, char[] dest, int destoff) static intgetOffsetAfter(CharSequence text, int offset) static intgetOffsetBefore(CharSequence text, int offset) static intReturns the length that the specified CharSequence would have if spaces and ASCII control characters were trimmed from the start and end, as byString.trim().static StringhtmlEncode(String s) Html-encode the string.static intindexOf(CharSequence s, char ch) static intindexOf(CharSequence s, char ch, int start) static intindexOf(CharSequence s, char ch, int start, int end) static intindexOf(CharSequence s, CharSequence needle) static intindexOf(CharSequence s, CharSequence needle, int start) static intindexOf(CharSequence s, CharSequence needle, int start, int end) static boolean判断字符串是否为空白static booleanisDigitsOnly(CharSequence str) 返回给定的CharSequence是否只包含数字static booleanisEmpty(@Nullable CharSequence str) Returns true if the string is null or 0-length.static booleanisGraphic(CharSequence str) 返回给定的CharSequence是否包含任何可打印字符static booleanisPrintableAscii(char c) 返回给定的字符是否为可打印的 ASCII 码static boolean返回给定的字符序列是否全是可打印的 ASCII 码static Stringjoin(@NotNull CharSequence delimiter, @NotNull Iterable tokens) Returns a string containing the tokens joined by delimiters.static Stringjoin(@NotNull CharSequence delimiter, @NotNull Object[] tokens) Returns a string containing the tokens joined by delimiters.static intlastIndexOf(CharSequence s, char ch) static intlastIndexOf(CharSequence s, char ch, int last) static intlastIndexOf(CharSequence s, char ch, int start, int last) static int返回给定字符串的长度static StringnullIfEmpty(@Nullable String str) 如果给定字符串为Empty,则返回 nullstatic longpackRangeInLong(int start, int end) Pack 2 int values into a long, useful as a return value for a rangestatic booleanregionMatches(CharSequence one, int toffset, CharSequence two, int ooffset, int len) static StringsafeIntern(String s) static String[]This method yields the same result astext.split(expression, -1)except that iftext.isEmpty()then this method returns an empty array whereas"".split(expression, -1)would have returned an array with a single"".static String[]Splits a string on a pattern.static Stringsubstring(CharSequence source, int start, int end) Create a new String object containing the given range of characters from the source string.static <T extends CharSequence>
TtrimToSize(T text, @org.jetbrains.annotations.Range(from=1L, to=2147483647L) int size) Trims the text tosizelength.static intunpackRangeEndFromLong(long range) Get the end value from a range packed in a long bypackRangeInLong(int, int)static intunpackRangeStartFromLong(long range) Get the start value from a range packed in a long bypackRangeInLong(int, int)static @Nullable StringwithoutPrefix(@Nullable String prefix, @Nullable String str) static voidwrap(StringBuilder builder, String start, String end)
-
方法详细资料
-
getChars
-
indexOf
-
indexOf
-
indexOf
-
lastIndexOf
-
lastIndexOf
-
lastIndexOf
-
indexOf
-
indexOf
-
indexOf
-
regionMatches
public static boolean regionMatches(CharSequence one, int toffset, CharSequence two, int ooffset, int len) -
substring
Create a new String object containing the given range of characters from the source string. This is different than simply callingCharSequence.subSequencein that it does not preserve any style runs in the source sequence, allowing a more efficient implementation. -
join
public static String join(@NotNull @NotNull CharSequence delimiter, @NotNull @NotNull Object[] tokens) Returns a string containing the tokens joined by delimiters.- 参数:
delimiter- a CharSequence that will be inserted between the tokens. If null, the string "null" will be used as the delimiter.tokens- an array objects to be joined. Strings will be formed from the objects by calling object.toString(). If tokens is null, a NullPointerException will be thrown. If tokens is an empty array, an empty string will be returned.
-
join
public static String join(@NotNull @NotNull CharSequence delimiter, @NotNull @NotNull Iterable tokens) Returns a string containing the tokens joined by delimiters.- 参数:
delimiter- a CharSequence that will be inserted between the tokens. If null, the string "null" will be used as the delimiter.tokens- an array objects to be joined. Strings will be formed from the objects by calling object.toString(). If tokens is null, a NullPointerException will be thrown. If tokens is empty, an empty string will be returned.
-
split
This method yields the same result astext.split(expression, -1)except that iftext.isEmpty()then this method returns an empty array whereas"".split(expression, -1)would have returned an array with a single"". The-1means that trailing empty Strings are not removed from the result; for example split("a,", "," ) returns {"a", ""}. Note that whether a leading zero-width match can result in a leading""depends on whether your app<= 28; seePattern.split(CharSequence, int).- 参数:
text- the string to splitexpression- the regular expression to match- 返回:
- an array of strings. The array will be empty if text is empty
- 抛出:
NullPointerException- if expression or text is null
-
split
Splits a string on a pattern. This method yields the same result aspattern.split(text, -1)except that iftext.isEmpty()then this method returns an empty array whereaspattern.split("", -1)would have returned an array with a single"". The-1means that trailing empty Strings are not removed from the result; Note that whether a leading zero-width match can result in a leading""depends an SDK version}<= 28; seePattern.split(CharSequence, int).- 参数:
text- the string to splitpattern- the regular expression to match- 返回:
- an array of strings. The array will be empty if text is empty
- 抛出:
NullPointerException- if expression or text is null
-
isEmpty
Returns true if the string is null or 0-length.- 参数:
str- the string to be examined- 返回:
- true if str is null or zero length
-
nullIfEmpty
如果给定字符串为Empty,则返回 null -
emptyIfNull
如果给定字符串为null,则返回 "" -
firstNotEmpty
@NotNull public static @NotNull String firstNotEmpty(@Nullable @Nullable String a, @NotNull @NotNull String b) 如果第一个字符串不为Empty,则返回第一个字符串,返回第二个字符串的非null形式(为null则返回"") -
length
返回给定字符串的长度- 返回:
s为 null 的情况下返回 0,否则返回其长度
-
safeIntern
- 返回:
- interned string if it's null.
-
getTrimmedLength
Returns the length that the specified CharSequence would have if spaces and ASCII control characters were trimmed from the start and end, as byString.trim(). -
equals
Returns true if a and b are equal, including if they are both null.Note: In platform versions 1.1 and earlier, this method only worked well if both the arguments were instances of String.
- 参数:
a- first CharSequence to checkb- second CharSequence to check- 返回:
- true if a and b are equal
-
getOffsetBefore
-
getOffsetAfter
-
htmlEncode
Html-encode the string.- 参数:
s- the string to be encoded- 返回:
- the encoded string
-
concat
拼接若干个字符序列- 返回:
- 当
text为null时,返回""
-
isGraphic
返回给定的CharSequence是否包含任何可打印字符- 返回:
- true 表示
str中包含可打印字符
-
isDigitsOnly
返回给定的CharSequence是否只包含数字- 返回:
- true 表示
str中只包含数字
-
isPrintableAscii
public static boolean isPrintableAscii(char c) 返回给定的字符是否为可打印的 ASCII 码- 返回:
- true 表示
c是可打印的 ASCII 码
-
isPrintableAsciiOnly
返回给定的字符序列是否全是可打印的 ASCII 码- 返回:
- true 表示
str中全是可打印的 ASCII 码
-
delimitedStringContains
判断带分隔符的列表是否包含特定项(不分配内存)- 参数:
delimitedString- 包含分隔符的列表delimiter- 分隔符item- 特定项
-
packRangeInLong
public static long packRangeInLong(int start, int end) Pack 2 int values into a long, useful as a return value for a range -
unpackRangeStartFromLong
public static int unpackRangeStartFromLong(long range) Get the start value from a range packed in a long bypackRangeInLong(int, int) -
unpackRangeEndFromLong
public static int unpackRangeEndFromLong(long range) Get the end value from a range packed in a long bypackRangeInLong(int, int) -
wrap
-
trimToSize
@Nullable public static <T extends CharSequence> T trimToSize(@Nullable T text, @org.jetbrains.annotations.Range(from=1L, to=2147483647L) int size) Trims the text tosizelength. Returns the string as it is if the length() is smaller thansize. If chars atsize-1andsizeis a surrogate pair, returns a CharSequence of lengthsize-1.- 参数:
size- length of the result, should be greater than 0
-
withoutPrefix
-
isBlank
判断字符串是否为空白- 参数:
str- 给定字符串- 返回:
- true表示
str为空白
-