public class TextUtils extends Object
android.text.TextUtil| 限定符和类型 | 类和说明 |
|---|---|
static interface |
TextUtils.StringSplitter
An interface for splitting strings according to rules that are opaque to the user of this
interface.
|
static class |
TextUtils.TruncateAt |
| 限定符和类型 | 方法和说明 |
|---|---|
static @NotNull CharSequence |
concat(CharSequence... text)
拼接若干个字符序列
|
static boolean |
delimitedStringContains(String delimitedString,
char delimiter,
String item)
判断带分隔符的列表是否包含特定项(不分配内存)
|
static String |
emptyIfNull(@Nullable String str)
如果给定字符串为null,则返回 ""
|
static boolean |
equals(CharSequence a,
CharSequence b)
Returns true if a and b are equal, including if they are both null.
|
static @NotNull String |
firstNotEmpty(@Nullable String a,
@NotNull String b)
如果第一个字符串不为Empty,则返回第一个字符串,返回第二个字符串的非null形式(为null则返回"")
|
static void |
getChars(CharSequence s,
int start,
int end,
char[] dest,
int destoff) |
static int |
getOffsetAfter(CharSequence text,
int offset) |
static int |
getOffsetBefore(CharSequence text,
int offset) |
static int |
getTrimmedLength(CharSequence s)
Returns the length that the specified CharSequence would have if
spaces and ASCII control characters were trimmed from the start and end,
as by
String.trim(). |
static String |
htmlEncode(String s)
Html-encode the string.
|
static int |
indexOf(CharSequence s,
char ch) |
static int |
indexOf(CharSequence s,
char ch,
int start) |
static int |
indexOf(CharSequence s,
char ch,
int start,
int end) |
static int |
indexOf(CharSequence s,
CharSequence needle) |
static int |
indexOf(CharSequence s,
CharSequence needle,
int start) |
static int |
indexOf(CharSequence s,
CharSequence needle,
int start,
int end) |
static boolean |
isBlank(String str)
判断字符串是否为空白
|
static boolean |
isDigitsOnly(CharSequence str)
返回给定的CharSequence是否只包含数字
|
static boolean |
isEmpty(@Nullable CharSequence str)
Returns true if the string is null or 0-length.
|
static boolean |
isGraphic(CharSequence str)
返回给定的CharSequence是否包含任何可打印字符
|
static boolean |
isPrintableAscii(char c)
返回给定的字符是否为可打印的 ASCII 码
|
static boolean |
isPrintableAsciiOnly(CharSequence str)
返回给定的字符序列是否全是可打印的 ASCII 码
|
static String |
join(@NotNull CharSequence delimiter,
@NotNull Iterable tokens)
Returns a string containing the tokens joined by delimiters.
|
static String |
join(@NotNull CharSequence delimiter,
@NotNull Object[] tokens)
Returns a string containing the tokens joined by delimiters.
|
static int |
lastIndexOf(CharSequence s,
char ch) |
static int |
lastIndexOf(CharSequence s,
char ch,
int last) |
static int |
lastIndexOf(CharSequence s,
char ch,
int start,
int last) |
static int |
length(@Nullable String s)
返回给定字符串的长度
|
static String |
nullIfEmpty(@Nullable String str)
如果给定字符串为Empty,则返回 null
|
static long |
packRangeInLong(int start,
int end)
Pack 2 int values into a long, useful as a return value for a range
|
static boolean |
regionMatches(CharSequence one,
int toffset,
CharSequence two,
int ooffset,
int len) |
static String |
safeIntern(String s) |
static String[] |
split(String text,
Pattern pattern)
Splits a string on a pattern.
|
static String[] |
split(String text,
String expression)
This method yields the same result as
text.split(expression, -1) except that if
text.isEmpty() then this method returns an empty array whereas
"".split(expression, -1) would have returned an array with a single "". |
static String |
substring(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> |
trimToSize(T text,
@Range(from=1L,to=2147483647L) int size)
Trims the text to
size length. |
static int |
unpackRangeEndFromLong(long range)
Get the end value from a range packed in a long by
packRangeInLong(int, int) |
static int |
unpackRangeStartFromLong(long range)
Get the start value from a range packed in a long by
packRangeInLong(int, int) |
static @Nullable String |
withoutPrefix(@Nullable String prefix,
@Nullable String str) |
static void |
wrap(StringBuilder builder,
String start,
String end)
|
public static void getChars(CharSequence s, int start, int end, char[] dest, int destoff)
public static int indexOf(CharSequence s, char ch)
public static int indexOf(CharSequence s, char ch, int start)
public static int indexOf(CharSequence s, char ch, int start, int end)
public static int lastIndexOf(CharSequence s, char ch)
public static int lastIndexOf(CharSequence s, char ch, int last)
public static int lastIndexOf(CharSequence s, char ch, int start, int last)
public static int indexOf(CharSequence s, CharSequence needle)
public static int indexOf(CharSequence s, CharSequence needle, int start)
public static int indexOf(CharSequence s, CharSequence needle, int start, int end)
public static boolean regionMatches(CharSequence one, int toffset, CharSequence two, int ooffset, int len)
public static String substring(CharSequence source, int start, int end)
CharSequence.subSequence
in that it does not preserve any style runs in the source sequence,
allowing a more efficient implementation.public static String join(@NotNull @NotNull CharSequence delimiter, @NotNull @NotNull Object[] tokens)
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.public static String join(@NotNull @NotNull CharSequence delimiter, @NotNull @NotNull Iterable tokens)
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.public static String[] split(String text, String expression)
text.split(expression, -1) except that if
text.isEmpty() then this method returns an empty array whereas
"".split(expression, -1) would have returned an array with a single "".
The -1 means 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; see Pattern.split(CharSequence, int).text - the string to splitexpression - the regular expression to matchNullPointerException - if expression or text is nullpublic static String[] split(String text, Pattern pattern)
pattern.split(text, -1) except that if text.isEmpty() then this method
returns an empty array whereas pattern.split("", -1) would have returned an array
with a single "".
The -1 means 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; see Pattern.split(CharSequence, int).text - the string to splitpattern - the regular expression to matchNullPointerException - if expression or text is nullpublic static boolean isEmpty(@Nullable
@Nullable CharSequence str)
str - the string to be examined@NotNull public static @NotNull String firstNotEmpty(@Nullable @Nullable String a, @NotNull @NotNull String b)
public static int length(@Nullable
@Nullable String s)
public static int getTrimmedLength(CharSequence s)
String.trim().public static boolean equals(CharSequence a, CharSequence b)
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 checkpublic static int getOffsetBefore(CharSequence text, int offset)
public static int getOffsetAfter(CharSequence text, int offset)
public static String htmlEncode(String s)
s - the string to be encoded@NotNull public static @NotNull CharSequence concat(CharSequence... text)
null 时,返回 ""public static boolean isGraphic(CharSequence str)
public static boolean isDigitsOnly(CharSequence str)
public static boolean isPrintableAscii(char c)
public static boolean isPrintableAsciiOnly(CharSequence str)
public static boolean delimitedStringContains(String delimitedString, char delimiter, String item)
delimitedString - 包含分隔符的列表delimiter - 分隔符item - 特定项public static long packRangeInLong(int start,
int end)
public static int unpackRangeStartFromLong(long range)
packRangeInLong(int, int)public static int unpackRangeEndFromLong(long range)
packRangeInLong(int, int)public static void wrap(StringBuilder builder, String start, String end)
@Nullable public static <T extends CharSequence> T trimToSize(@Nullable T text, @Range(from=1L,to=2147483647L) int size)
size length. Returns the string as it is if the length() is
smaller than size. If chars at size-1 and size is a surrogate
pair, returns a CharSequence of length size-1.size - length of the result, should be greater than 0@Nullable public static @Nullable String withoutPrefix(@Nullable @Nullable String prefix, @Nullable @Nullable String str)
public static boolean isBlank(String str)
str - 给定字符串Copyright © 2021. All rights reserved.