类 TextUtils

java.lang.Object
org.beetl.core.util.TextUtils

public class TextUtils extends Object
文本工具类 修改自 android.text.TextUtil
  • 方法详细资料

    • getChars

      public static void getChars(CharSequence s, int start, int end, char[] dest, int destoff)
    • indexOf

      public static int indexOf(CharSequence s, char ch)
    • indexOf

      public static int indexOf(CharSequence s, char ch, int start)
    • indexOf

      public static int indexOf(CharSequence s, char ch, int start, int end)
    • lastIndexOf

      public static int lastIndexOf(CharSequence s, char ch)
    • lastIndexOf

      public static int lastIndexOf(CharSequence s, char ch, int last)
    • lastIndexOf

      public static int lastIndexOf(CharSequence s, char ch, int start, int last)
    • indexOf

      public static int indexOf(CharSequence s, CharSequence needle)
    • indexOf

      public static int indexOf(CharSequence s, CharSequence needle, int start)
    • indexOf

      public static int indexOf(CharSequence s, CharSequence needle, int start, int end)
    • regionMatches

      public static boolean regionMatches(CharSequence one, int toffset, CharSequence two, int ooffset, int len)
    • substring

      public static String substring(CharSequence source, int start, int end)
      Create a new String object containing the given range of characters from the source string. This is different than simply calling CharSequence.subSequence in 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

      public 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 "". 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 split
      expression - 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

      public static String[] split(String text, Pattern pattern)
      Splits a string on a pattern. This method yields the same result as 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 split
      pattern - 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

      public static boolean isEmpty(@Nullable @Nullable CharSequence str)
      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

      public static String nullIfEmpty(@Nullable @Nullable String str)
      如果给定字符串为Empty,则返回 null
    • emptyIfNull

      public static String emptyIfNull(@Nullable @Nullable String str)
      如果给定字符串为null,则返回 ""
    • firstNotEmpty

      @NotNull public static @NotNull String firstNotEmpty(@Nullable @Nullable String a, @NotNull @NotNull String b)
      如果第一个字符串不为Empty,则返回第一个字符串,返回第二个字符串的非null形式(为null则返回"")
    • length

      public static int length(@Nullable @Nullable String s)
      返回给定字符串的长度
      返回:
      s 为 null 的情况下返回 0,否则返回其长度
    • safeIntern

      public static String safeIntern(String s)
      返回:
      interned string if it's null.
    • getTrimmedLength

      public 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().
    • equals

      public static boolean equals(CharSequence a, CharSequence b)
      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 check
      b - second CharSequence to check
      返回:
      true if a and b are equal
    • getOffsetBefore

      public static int getOffsetBefore(CharSequence text, int offset)
    • getOffsetAfter

      public static int getOffsetAfter(CharSequence text, int offset)
    • htmlEncode

      public static String htmlEncode(String s)
      Html-encode the string.
      参数:
      s - the string to be encoded
      返回:
      the encoded string
    • concat

      @NotNull public static @NotNull CharSequence concat(CharSequence... text)
      拼接若干个字符序列
      返回:
      textnull 时,返回 ""
    • isGraphic

      public static boolean isGraphic(CharSequence str)
      返回给定的CharSequence是否包含任何可打印字符
      返回:
      true 表示 str 中包含可打印字符
    • isDigitsOnly

      public static boolean isDigitsOnly(CharSequence str)
      返回给定的CharSequence是否只包含数字
      返回:
      true 表示 str 中只包含数字
    • isPrintableAscii

      public static boolean isPrintableAscii(char c)
      返回给定的字符是否为可打印的 ASCII 码
      返回:
      true 表示 c 是可打印的 ASCII 码
    • isPrintableAsciiOnly

      public static boolean isPrintableAsciiOnly(CharSequence str)
      返回给定的字符序列是否全是可打印的 ASCII 码
      返回:
      true 表示 str 中全是可打印的 ASCII 码
    • delimitedStringContains

      public static boolean delimitedStringContains(String delimitedString, char delimiter, String item)
      判断带分隔符的列表是否包含特定项(不分配内存)
      参数:
      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 by packRangeInLong(int, int)
      另请参阅:
    • unpackRangeEndFromLong

      public static int unpackRangeEndFromLong(long range)
      Get the end value from a range packed in a long by packRangeInLong(int, int)
      另请参阅:
    • wrap

      public static void wrap(StringBuilder builder, String start, String end)
      Prepends start and appends end to a given StringBuilder
    • 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 to 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
    • withoutPrefix

      @Nullable public static @Nullable String withoutPrefix(@Nullable @Nullable String prefix, @Nullable @Nullable String str)
    • isBlank

      public static boolean isBlank(String str)
      判断字符串是否为空白
      参数:
      str - 给定字符串
      返回:
      true表示 str 为空白