# TextUtils

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Nested Classes](https://developer.android.com/reference/android/text/TextUtils#nestedclasses)\|[Constants](https://developer.android.com/reference/android/text/TextUtils#constants)\|[Fields](https://developer.android.com/reference/android/text/TextUtils#lfields)\|[Methods](https://developer.android.com/reference/android/text/TextUtils#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/text/TextUtils#inhmethods)  

# TextUtils

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/text/TextUtils "View this page in Kotlin")\|Java

`
public


class
TextUtils
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.text.TextUtils |

<br />

*** ** * ** ***

## Summary

|                                                                                                      ### Nested classes                                                                                                      ||
|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` interface` | [TextUtils.EllipsizeCallback](https://developer.android.com/reference/android/text/TextUtils.EllipsizeCallback) <br />                                                                                         |
| ` class`     | [TextUtils.SimpleStringSplitter](https://developer.android.com/reference/android/text/TextUtils.SimpleStringSplitter) A simple string splitter.                                                                |
| ` interface` | [TextUtils.StringSplitter](https://developer.android.com/reference/android/text/TextUtils.StringSplitter) An interface for splitting strings according to rules that are opaque to the user of this interface. |

|                                                                                                                                                                  ### Constants                                                                                                                                                                  ||
|-------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | [CAP_MODE_CHARACTERS](https://developer.android.com/reference/android/text/TextUtils#CAP_MODE_CHARACTERS) Capitalization mode for[getCapsMode(CharSequence, int, int)](https://developer.android.com/reference/android/text/TextUtils#getCapsMode(java.lang.CharSequence,%20int,%20int)): capitalize all characters.                     |
| `int` | [CAP_MODE_SENTENCES](https://developer.android.com/reference/android/text/TextUtils#CAP_MODE_SENTENCES) Capitalization mode for[getCapsMode(CharSequence, int, int)](https://developer.android.com/reference/android/text/TextUtils#getCapsMode(java.lang.CharSequence,%20int,%20int)): capitalize the first character of each sentence. |
| `int` | [CAP_MODE_WORDS](https://developer.android.com/reference/android/text/TextUtils#CAP_MODE_WORDS) Capitalization mode for[getCapsMode(CharSequence, int, int)](https://developer.android.com/reference/android/text/TextUtils#getCapsMode(java.lang.CharSequence,%20int,%20int)): capitalize the first character of all words.             |
| `int` | [SAFE_STRING_FLAG_FIRST_LINE](https://developer.android.com/reference/android/text/TextUtils#SAFE_STRING_FLAG_FIRST_LINE) Return only first line of text (truncate at first newline).                                                                                                                                                    |
| `int` | [SAFE_STRING_FLAG_SINGLE_LINE](https://developer.android.com/reference/android/text/TextUtils#SAFE_STRING_FLAG_SINGLE_LINE) Force entire string into single line of text (no newlines).                                                                                                                                                  |
| `int` | [SAFE_STRING_FLAG_TRIM](https://developer.android.com/reference/android/text/TextUtils#SAFE_STRING_FLAG_TRIM) Remove[whitespace](https://developer.android.com/reference/java/lang/Character#isWhitespace(int))and non-breaking spaces from the edges of the label.                                                                      |

|                                                                                                                                                    ### Fields                                                                                                                                                     ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------|
| ` public static final `[Creator](https://developer.android.com/reference/android/os/Parcelable.Creator)`<`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)`>` | [CHAR_SEQUENCE_CREATOR](https://developer.android.com/reference/android/text/TextUtils#CHAR_SEQUENCE_CREATOR) <br /> |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ### Public methods                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ||
|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[commaEllipsize](https://developer.android.com/reference/android/text/TextUtils#commaEllipsize(java.lang.CharSequence,%20android.text.TextPaint,%20float,%20java.lang.String,%20java.lang.String))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` text, `[TextPaint](https://developer.android.com/reference/android/text/TextPaint)` p, float avail, `[String](https://developer.android.com/reference/java/lang/String)` oneMore, `[String](https://developer.android.com/reference/java/lang/String)` more) ` *This method was deprecated in API level 26. Do not use. This is not internationalized, and has known issues with right-to-left text, languages that have more than one plural form, languages that use a different character as a comma-like separator, etc. Use[listEllipsize(Context, List, String, TextPaint, float, int)](https://developer.android.com/reference/android/text/TextUtils#listEllipsize(android.content.Context,%20java.util.List<java.lang.CharSequence>,%20java.lang.String,%20android.text.TextPaint,%20float,%20int))instead.* |
| ` static `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[concat](https://developer.android.com/reference/android/text/TextUtils#concat(java.lang.CharSequence[]))`(`[CharSequence...](https://developer.android.com/reference/java/lang/CharSequence)` text) ` Returns a CharSequence concatenating the specified CharSequences, retaining their spans if any.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` static void`                                                                           | ` `[copySpansFrom](https://developer.android.com/reference/android/text/TextUtils#copySpansFrom(android.text.Spanned,%20int,%20int,%20java.lang.Class,%20android.text.Spannable,%20int))`(`[Spanned](https://developer.android.com/reference/android/text/Spanned)` source, int start, int end, `[Class](https://developer.android.com/reference/java/lang/Class)`<T> kind, `[Spannable](https://developer.android.com/reference/android/text/Spannable)` dest, int destoff) ` Copies the spans from the region`start...end`in`source`to the region`destoff...destoff+end-start`in`dest`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` static void`                                                                           | ` `[dumpSpans](https://developer.android.com/reference/android/text/TextUtils#dumpSpans(java.lang.CharSequence,%20android.util.Printer,%20java.lang.String))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` cs, `[Printer](https://developer.android.com/reference/android/util/Printer)` printer, `[String](https://developer.android.com/reference/java/lang/String)` prefix) ` Debugging tool to print the spans in a CharSequence.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` static `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[ellipsize](https://developer.android.com/reference/android/text/TextUtils#ellipsize(java.lang.CharSequence,%20android.text.TextPaint,%20float,%20android.text.TextUtils.TruncateAt))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` text, `[TextPaint](https://developer.android.com/reference/android/text/TextPaint)` p, float avail, `[TextUtils.TruncateAt](https://developer.android.com/reference/android/text/TextUtils.TruncateAt)` where) ` Returns the original text if it fits in the specified width given the properties of the specified Paint, or, if it does not fit, a truncated copy with ellipsis character added at the specified edge or center.                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` static `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[ellipsize](https://developer.android.com/reference/android/text/TextUtils#ellipsize(java.lang.CharSequence,%20android.text.TextPaint,%20float,%20android.text.TextUtils.TruncateAt,%20boolean,%20android.text.TextUtils.EllipsizeCallback))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` text, `[TextPaint](https://developer.android.com/reference/android/text/TextPaint)` paint, float avail, `[TextUtils.TruncateAt](https://developer.android.com/reference/android/text/TextUtils.TruncateAt)` where, boolean preserveLength, `[TextUtils.EllipsizeCallback](https://developer.android.com/reference/android/text/TextUtils.EllipsizeCallback)` callback) ` Returns the original text if it fits in the specified width given the properties of the specified Paint, or, if it does not fit, a copy with ellipsis character added at the specified edge or center.                                                                                                                                                                                             |
| ` static boolean`                                                                        | ` `[equals](https://developer.android.com/reference/android/text/TextUtils#equals(java.lang.CharSequence,%20java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` a, `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` b) ` Returns true if a and b are equal, including if they are both null.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ` static `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[expandTemplate](https://developer.android.com/reference/android/text/TextUtils#expandTemplate(java.lang.CharSequence,%20java.lang.CharSequence[]))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` template, `[CharSequence...](https://developer.android.com/reference/java/lang/CharSequence)` values) ` Replace instances of "\^1", "\^2", etc.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ` static int`                                                                            | ` `[getCapsMode](https://developer.android.com/reference/android/text/TextUtils#getCapsMode(java.lang.CharSequence,%20int,%20int))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` cs, int off, int reqModes) ` Determine what caps mode should be in effect at the current offset in the text.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ` static void`                                                                           | ` `[getChars](https://developer.android.com/reference/android/text/TextUtils#getChars(java.lang.CharSequence,%20int,%20int,%20char[],%20int))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` s, int start, int end, char[] dest, int destoff) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ` static int`                                                                            | ` `[getLayoutDirectionFromLocale](https://developer.android.com/reference/android/text/TextUtils#getLayoutDirectionFromLocale(java.util.Locale))`(`[Locale](https://developer.android.com/reference/java/util/Locale)` locale) ` Return the layout direction for a given Locale                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` static int`                                                                            | ` `[getOffsetAfter](https://developer.android.com/reference/android/text/TextUtils#getOffsetAfter(java.lang.CharSequence,%20int))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` text, int offset) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` static int`                                                                            | ` `[getOffsetBefore](https://developer.android.com/reference/android/text/TextUtils#getOffsetBefore(java.lang.CharSequence,%20int))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` text, int offset) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` static `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[getReverse](https://developer.android.com/reference/android/text/TextUtils#getReverse(java.lang.CharSequence,%20int,%20int))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` source, int start, int end) ` *This method was deprecated in API level 24. Do not use.*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` static int`                                                                            | ` `[getTrimmedLength](https://developer.android.com/reference/android/text/TextUtils#getTrimmedLength(java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/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](https://developer.android.com/reference/java/lang/String#trim()).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ` static `[String](https://developer.android.com/reference/java/lang/String)             | ` `[htmlEncode](https://developer.android.com/reference/android/text/TextUtils#htmlEncode(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` s) ` Html-encode the string.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` static int`                                                                            | ` `[indexOf](https://developer.android.com/reference/android/text/TextUtils#indexOf(java.lang.CharSequence,%20char,%20int,%20int))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` s, char ch, int start, int end) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` static int`                                                                            | ` `[indexOf](https://developer.android.com/reference/android/text/TextUtils#indexOf(java.lang.CharSequence,%20java.lang.CharSequence,%20int,%20int))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` s, `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` needle, int start, int end) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ` static int`                                                                            | ` `[indexOf](https://developer.android.com/reference/android/text/TextUtils#indexOf(java.lang.CharSequence,%20java.lang.CharSequence,%20int))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` s, `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` needle, int start) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ` static int`                                                                            | ` `[indexOf](https://developer.android.com/reference/android/text/TextUtils#indexOf(java.lang.CharSequence,%20java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` s, `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` needle) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` static int`                                                                            | ` `[indexOf](https://developer.android.com/reference/android/text/TextUtils#indexOf(java.lang.CharSequence,%20char,%20int))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` s, char ch, int start) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` static int`                                                                            | ` `[indexOf](https://developer.android.com/reference/android/text/TextUtils#indexOf(java.lang.CharSequence,%20char))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` s, char ch) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ` static boolean`                                                                        | ` `[isDigitsOnly](https://developer.android.com/reference/android/text/TextUtils#isDigitsOnly(java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` str) ` Returns whether the given CharSequence contains only digits.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` static boolean`                                                                        | ` `[isEmpty](https://developer.android.com/reference/android/text/TextUtils#isEmpty(java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` str) ` Returns true if the string is null or 0-length.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ` static boolean`                                                                        | ` `[isGraphic](https://developer.android.com/reference/android/text/TextUtils#isGraphic(java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` str) ` Returns whether the given CharSequence contains any printable characters.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ` static boolean`                                                                        | ` `[isGraphic](https://developer.android.com/reference/android/text/TextUtils#isGraphic(char))`(char c) ` *This method was deprecated in API level 24. Use[isGraphic(java.lang.CharSequence)](https://developer.android.com/reference/android/text/TextUtils#isGraphic(java.lang.CharSequence))instead.*                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| ` static `[String](https://developer.android.com/reference/java/lang/String)             | ` `[join](https://developer.android.com/reference/android/text/TextUtils#join(java.lang.CharSequence,%20java.lang.Iterable))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` delimiter, `[Iterable](https://developer.android.com/reference/java/lang/Iterable)`<T> tokens) ` Returns a string containing the tokens joined by delimiters.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` static `[String](https://developer.android.com/reference/java/lang/String)             | ` `[join](https://developer.android.com/reference/android/text/TextUtils#join(java.lang.CharSequence,%20java.lang.Object[]))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` delimiter, `[Object[]](https://developer.android.com/reference/java/lang/Object)` tokens) ` Returns a string containing the tokens joined by delimiters.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| ` static int`                                                                            | ` `[lastIndexOf](https://developer.android.com/reference/android/text/TextUtils#lastIndexOf(java.lang.CharSequence,%20char,%20int))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` s, char ch, int last) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ` static int`                                                                            | ` `[lastIndexOf](https://developer.android.com/reference/android/text/TextUtils#lastIndexOf(java.lang.CharSequence,%20char))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` s, char ch) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ` static int`                                                                            | ` `[lastIndexOf](https://developer.android.com/reference/android/text/TextUtils#lastIndexOf(java.lang.CharSequence,%20char,%20int,%20int))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` s, char ch, int start, int last) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` static `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[listEllipsize](https://developer.android.com/reference/android/text/TextUtils#listEllipsize(android.content.Context,%20java.util.List<java.lang.CharSequence>,%20java.lang.String,%20android.text.TextPaint,%20float,%20int))`(`[Context](https://developer.android.com/reference/android/content/Context)` context, `[List](https://developer.android.com/reference/java/util/List)`<`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)`> elements, `[String](https://developer.android.com/reference/java/lang/String)` separator, `[TextPaint](https://developer.android.com/reference/android/text/TextPaint)` paint, float avail, int moreId) ` Formats a list of CharSequences by repeatedly inserting the separator between them, but stopping when the resulting sequence is too wide for the specified width.                                                                                                                                                                                                                                                       |
| ` static `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[makeSafeForPresentation](https://developer.android.com/reference/android/text/TextUtils#makeSafeForPresentation(java.lang.String,%20int,%20float,%20int))`(`[String](https://developer.android.com/reference/java/lang/String)` unclean, int maxCharactersToConsider, float ellipsizeDip, int flags) ` Remove html, remove bad characters, and truncate string.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ` static boolean`                                                                        | ` `[regionMatches](https://developer.android.com/reference/android/text/TextUtils#regionMatches(java.lang.CharSequence,%20int,%20java.lang.CharSequence,%20int,%20int))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` one, int toffset, `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` two, int ooffset, int len) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` static `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[replace](https://developer.android.com/reference/android/text/TextUtils#replace(java.lang.CharSequence,%20java.lang.String[],%20java.lang.CharSequence[]))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` template, `[String[]](https://developer.android.com/reference/java/lang/String)` sources, `[CharSequence[]](https://developer.android.com/reference/java/lang/CharSequence)` destinations) ` Return a new CharSequence in which each of the source strings is replaced by the corresponding element of the destinations.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ` static `[String[]](https://developer.android.com/reference/java/lang/String)           | ` `[split](https://developer.android.com/reference/android/text/TextUtils#split(java.lang.String,%20java.util.regex.Pattern))`(`[String](https://developer.android.com/reference/java/lang/String)` text, `[Pattern](https://developer.android.com/reference/java/util/regex/Pattern)` pattern) ` Splits a string on a pattern.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` static `[String[]](https://developer.android.com/reference/java/lang/String)           | ` `[split](https://developer.android.com/reference/android/text/TextUtils#split(java.lang.String,%20java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` text, `[String](https://developer.android.com/reference/java/lang/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 `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[stringOrSpannedString](https://developer.android.com/reference/android/text/TextUtils#stringOrSpannedString(java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` source) `                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ` static `[String](https://developer.android.com/reference/java/lang/String)             | ` `[substring](https://developer.android.com/reference/android/text/TextUtils#substring(java.lang.CharSequence,%20int,%20int))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` source, int start, int end) ` Create a new String object containing the given range of characters from the source string.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` static void`                                                                           | ` `[writeToParcel](https://developer.android.com/reference/android/text/TextUtils#writeToParcel(java.lang.CharSequence,%20android.os.Parcel,%20int))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` cs, `[Parcel](https://developer.android.com/reference/android/os/Parcel)` p, int parcelableFlags) ` Flatten a CharSequence and whatever styles can be copied across processes into the parcel.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Constants

### CAP_MODE_CHARACTERS

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int CAP_MODE_CHARACTERS
```

Capitalization mode for[getCapsMode(CharSequence, int, int)](https://developer.android.com/reference/android/text/TextUtils#getCapsMode(java.lang.CharSequence,%20int,%20int)): capitalize all characters. This value is explicitly defined to be the same as[InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS](https://developer.android.com/reference/android/text/InputType#TYPE_TEXT_FLAG_CAP_CHARACTERS).

<br />

Constant Value: 4096 (0x00001000)  

### CAP_MODE_SENTENCES

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int CAP_MODE_SENTENCES
```

Capitalization mode for[getCapsMode(CharSequence, int, int)](https://developer.android.com/reference/android/text/TextUtils#getCapsMode(java.lang.CharSequence,%20int,%20int)): capitalize the first character of each sentence. This value is explicitly defined to be the same as[InputType.TYPE_TEXT_FLAG_CAP_SENTENCES](https://developer.android.com/reference/android/text/InputType#TYPE_TEXT_FLAG_CAP_SENTENCES).

<br />

Constant Value: 16384 (0x00004000)  

### CAP_MODE_WORDS

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int CAP_MODE_WORDS
```

Capitalization mode for[getCapsMode(CharSequence, int, int)](https://developer.android.com/reference/android/text/TextUtils#getCapsMode(java.lang.CharSequence,%20int,%20int)): capitalize the first character of all words. This value is explicitly defined to be the same as[InputType.TYPE_TEXT_FLAG_CAP_WORDS](https://developer.android.com/reference/android/text/InputType#TYPE_TEXT_FLAG_CAP_WORDS).

<br />

Constant Value: 8192 (0x00002000)  

### SAFE_STRING_FLAG_FIRST_LINE

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int SAFE_STRING_FLAG_FIRST_LINE
```

Return only first line of text (truncate at first newline). Cannot be set at the same time as[SAFE_STRING_FLAG_SINGLE_LINE](https://developer.android.com/reference/android/text/TextUtils#SAFE_STRING_FLAG_SINGLE_LINE).

<br />

**See also:**

- [makeSafeForPresentation(String, int, float, int)](https://developer.android.com/reference/android/text/TextUtils#makeSafeForPresentation(java.lang.String,%20int,%20float,%20int))

Constant Value: 4 (0x00000004)  

### SAFE_STRING_FLAG_SINGLE_LINE

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int SAFE_STRING_FLAG_SINGLE_LINE
```

Force entire string into single line of text (no newlines). Cannot be set at the same time as[SAFE_STRING_FLAG_FIRST_LINE](https://developer.android.com/reference/android/text/TextUtils#SAFE_STRING_FLAG_FIRST_LINE).

<br />

**See also:**

- [makeSafeForPresentation(String, int, float, int)](https://developer.android.com/reference/android/text/TextUtils#makeSafeForPresentation(java.lang.String,%20int,%20float,%20int))

Constant Value: 2 (0x00000002)  

### SAFE_STRING_FLAG_TRIM

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final int SAFE_STRING_FLAG_TRIM
```

Remove[whitespace](https://developer.android.com/reference/java/lang/Character#isWhitespace(int))and non-breaking spaces from the edges of the label.

<br />

**See also:**

- [makeSafeForPresentation(String, int, float, int)](https://developer.android.com/reference/android/text/TextUtils#makeSafeForPresentation(java.lang.String,%20int,%20float,%20int))

Constant Value: 1 (0x00000001)

## Fields

### CHAR_SEQUENCE_CREATOR

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static final Creator<CharSequence> CHAR_SEQUENCE_CREATOR
```

<br />

<br />

## Public methods

### commaEllipsize

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static CharSequence commaEllipsize (CharSequence text, 
                TextPaint p, 
                float avail, 
                String oneMore, 
                String more)
```

<br />

**This method was deprecated in API level 26.**   
Do not use. This is not internationalized, and has known issues with right-to-left text, languages that have more than one plural form, languages that use a different character as a comma-like separator, etc. Use[listEllipsize(Context, List, String, TextPaint, float, int)](https://developer.android.com/reference/android/text/TextUtils#listEllipsize(android.content.Context,%20java.util.List<java.lang.CharSequence>,%20java.lang.String,%20android.text.TextPaint,%20float,%20int))instead.

Converts a CharSequence of the comma-separated form "Andy, Bob, Charles, David" that is too wide to fit into the specified width into one like "Andy, Bob, 2 more".

<br />

|                                     Parameters                                     ||
|-----------|-------------------------------------------------------------------------|
| `text`    | `CharSequence`: the text to truncate <br />                             |
| `p`       | `TextPaint`: the Paint with which to measure the text <br />            |
| `avail`   | `float`: the horizontal width available for the text (in pixels) <br /> |
| `oneMore` | `String`: the string for "1 more" in the current locale <br />          |
| `more`    | `String`: the string for "%d more" in the current locale <br />         |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | <br /> |

### concat

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static CharSequence concat (CharSequence... text)
```

Returns a CharSequence concatenating the specified CharSequences, retaining their spans if any. If there are no parameters, an empty string will be returned. If the number of parameters is exactly one, that parameter is returned as output, even if it is null. If the number of parameters is at least two, any null CharSequence among the parameters is treated as if it was the string`"null"`. If there are paragraph spans in the source CharSequences that satisfy paragraph boundary requirements in the sources but would no longer satisfy them in the concatenated CharSequence, they may get extended in the resulting CharSequence or not retained.

<br />

|          Parameters           ||
|--------|-----------------------|
| `text` | `CharSequence` <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | <br /> |

### copySpansFrom

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static void copySpansFrom (Spanned source, 
                int start, 
                int end, 
                Class<T> kind, 
                Spannable dest, 
                int destoff)
```

Copies the spans from the region`start...end`in`source`to the region`destoff...destoff+end-start`in`dest`. Spans in`source`that begin before`start`or end after`end`but overlap this range are trimmed as if they began at`start`or ended at`end`.

<br />

|          Parameters           ||
|-----------|--------------------|
| `source`  | `Spanned` <br />   |
| `start`   | `int` <br />       |
| `end`     | `int` <br />       |
| `kind`    | `Class` <br />     |
| `dest`    | `Spannable` <br /> |
| `destoff` | `int` <br />       |

|                                                                             Throws                                                                              ||
|----------------------------------------------------------------------------------------------------------|-------------------------------------------------------|
| [IndexOutOfBoundsException](https://developer.android.com/reference/java/lang/IndexOutOfBoundsException) | if any of the copied spans are out of range in`dest`. |

### dumpSpans

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static void dumpSpans (CharSequence cs, 
                Printer printer, 
                String prefix)
```

Debugging tool to print the spans in a CharSequence. The output will be printed one span per line. If the CharSequence is not a Spanned, then the entire string will be printed on a single line.

<br />

|            Parameters            ||
|-----------|-----------------------|
| `cs`      | `CharSequence` <br /> |
| `printer` | `Printer` <br />      |
| `prefix`  | `String` <br />       |

### ellipsize

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static CharSequence ellipsize (CharSequence text, 
                TextPaint p, 
                float avail, 
                TextUtils.TruncateAt where)
```

Returns the original text if it fits in the specified width given the properties of the specified Paint, or, if it does not fit, a truncated copy with ellipsis character added at the specified edge or center.

<br />

|               Parameters               ||
|---------|-------------------------------|
| `text`  | `CharSequence` <br />         |
| `p`     | `TextPaint` <br />            |
| `avail` | `float` <br />                |
| `where` | `TextUtils.TruncateAt` <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | <br /> |

### ellipsize

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static CharSequence ellipsize (CharSequence text, 
                TextPaint paint, 
                float avail, 
                TextUtils.TruncateAt where, 
                boolean preserveLength, 
                TextUtils.EllipsizeCallback callback)
```

Returns the original text if it fits in the specified width given the properties of the specified Paint, or, if it does not fit, a copy with ellipsis character added at the specified edge or center. If`preserveLength`is specified, the returned copy will be padded with zero-width spaces to preserve the original length and offsets instead of truncating. If`callback`is non-null, it will be called to report the start and end of the ellipsized range. TextDirection is determined by the first strong directional character.

<br />

|                                    Parameters                                    ||
|------------------|----------------------------------------------------------------|
| `text`           | `CharSequence` <br />                                          |
| `paint`          | `TextPaint` <br />                                             |
| `avail`          | `float` <br />                                                 |
| `where`          | `TextUtils.TruncateAt` <br />                                  |
| `preserveLength` | `boolean` <br />                                               |
| `callback`       | `TextUtils.EllipsizeCallback`: This value may be`null`. <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | <br /> |

### equals

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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.*

<br />

<br />

|                                    Parameters                                     ||
|-----|------------------------------------------------------------------------------|
| `a` | `CharSequence`: first CharSequence to check This value may be`null`. <br />  |
| `b` | `CharSequence`: second CharSequence to check This value may be`null`. <br /> |

|                   Returns                   ||
|-----------|----------------------------------|
| `boolean` | true if a and b are equal <br /> |

### expandTemplate

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static CharSequence expandTemplate (CharSequence template, 
                CharSequence... values)
```

Replace instances of "\^1", "\^2", etc. in the`template`CharSequence with the corresponding`values`. "\^\^" is used to produce a single caret in the output. Only up to 9 replacement values are supported, "\^10" will be produce the first replacement value followed by a '0'.

<br />

|                                                                      Parameters                                                                      ||
|------------|------------------------------------------------------------------------------------------------------------------------------------------|
| `template` | `CharSequence`: the input text containing "\^1"-style placeholder values. This object is not modified; a copy is returned. <br />        |
| `values`   | `CharSequence`: CharSequences substituted into the template. The first is substituted for "\^1", the second for "\^2", and so on. <br /> |

|                                                                    Returns                                                                    ||
|--------------------------------------------------------------------------------|---------------------------------------------------------------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | the new CharSequence produced by doing the replacement <br /> |

|                                                                                                 Throws                                                                                                 ||
|--------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if the template requests a value that was not provided, or if more than 9 values are provided. |

### getCapsMode

Added in[API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static int getCapsMode (CharSequence cs, 
                int off, 
                int reqModes)
```

Determine what caps mode should be in effect at the current offset in the text. Only the mode bits set in<var translate="no">reqModes</var>will be checked. Note that the caps mode flags here are explicitly defined to match those in[InputType](https://developer.android.com/reference/android/text/InputType).

<br />

|                                                                                                                                                                                             Parameters                                                                                                                                                                                             ||
|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `cs`       | `CharSequence`: The text that should be checked for caps modes. <br />                                                                                                                                                                                                                                                                                                                 |
| `off`      | `int`: Location in the text at which to check. <br />                                                                                                                                                                                                                                                                                                                                  |
| `reqModes` | `int`: The modes to be checked: may be any combination of[CAP_MODE_CHARACTERS](https://developer.android.com/reference/android/text/TextUtils#CAP_MODE_CHARACTERS),[CAP_MODE_WORDS](https://developer.android.com/reference/android/text/TextUtils#CAP_MODE_WORDS), and[CAP_MODE_SENTENCES](https://developer.android.com/reference/android/text/TextUtils#CAP_MODE_SENTENCES). <br /> |

|                                                                                                                                                                                                                        Returns                                                                                                                                                                                                                         ||
|-------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | Returns the actual capitalization modes that can be in effect at the current position, which is any combination of[CAP_MODE_CHARACTERS](https://developer.android.com/reference/android/text/TextUtils#CAP_MODE_CHARACTERS),[CAP_MODE_WORDS](https://developer.android.com/reference/android/text/TextUtils#CAP_MODE_WORDS), and[CAP_MODE_SENTENCES](https://developer.android.com/reference/android/text/TextUtils#CAP_MODE_SENTENCES). <br /> |

### getChars

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

<br />

|            Parameters            ||
|-----------|-----------------------|
| `s`       | `CharSequence` <br /> |
| `start`   | `int` <br />          |
| `end`     | `int` <br />          |
| `dest`    | `char` <br />         |
| `destoff` | `int` <br />          |

### getLayoutDirectionFromLocale

Added in[API level 17](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static int getLayoutDirectionFromLocale (Locale locale)
```

Return the layout direction for a given Locale

<br />

|                                         Parameters                                         ||
|----------|----------------------------------------------------------------------------------|
| `locale` | `Locale`: the Locale for which we want the layout direction. Can be null. <br /> |

|                                                                                                                                                                                Returns                                                                                                                                                                                 ||
|-------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `int` | the layout direction. This may be one of:[View.LAYOUT_DIRECTION_LTR](https://developer.android.com/reference/android/view/View#LAYOUT_DIRECTION_LTR)or[View.LAYOUT_DIRECTION_RTL](https://developer.android.com/reference/android/view/View#LAYOUT_DIRECTION_RTL). Be careful: this code will need to be updated when vertical scripts will be supported <br /> |

### getOffsetAfter

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static int getOffsetAfter (CharSequence text, 
                int offset)
```

<br />

<br />

|           Parameters            ||
|----------|-----------------------|
| `text`   | `CharSequence` <br /> |
| `offset` | `int` <br />          |

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### getOffsetBefore

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static int getOffsetBefore (CharSequence text, 
                int offset)
```

<br />

<br />

|           Parameters            ||
|----------|-----------------------|
| `text`   | `CharSequence` <br /> |
| `offset` | `int` <br />          |

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### getReverse

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static CharSequence getReverse (CharSequence source, 
                int start, 
                int end)
```

<br />

**This method was deprecated in API level 24.**   
Do not use.

This function only reverses individual`char`s and not their associated spans. It doesn't support surrogate pairs (that correspond to non-BMP code points), combining sequences or conjuncts either.

<br />

|           Parameters            ||
|----------|-----------------------|
| `source` | `CharSequence` <br /> |
| `start`  | `int` <br />          |
| `end`    | `int` <br />          |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | <br /> |

### getTrimmedLength

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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](https://developer.android.com/reference/java/lang/String#trim()).

<br />

|         Parameters         ||
|-----|-----------------------|
| `s` | `CharSequence` <br /> |

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### htmlEncode

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static String htmlEncode (String s)
```

Html-encode the string.

<br />

|                   Parameters                   ||
|-----|-------------------------------------------|
| `s` | `String`: the string to be encoded <br /> |

|                                            Returns                                            ||
|--------------------------------------------------------------------|---------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | the encoded string <br /> |

### indexOf

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

<br />

|           Parameters           ||
|---------|-----------------------|
| `s`     | `CharSequence` <br /> |
| `ch`    | `char` <br />         |
| `start` | `int` <br />          |
| `end`   | `int` <br />          |

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### indexOf

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

<br />

|           Parameters            ||
|----------|-----------------------|
| `s`      | `CharSequence` <br /> |
| `needle` | `CharSequence` <br /> |
| `start`  | `int` <br />          |
| `end`    | `int` <br />          |

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### indexOf

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

<br />

|           Parameters            ||
|----------|-----------------------|
| `s`      | `CharSequence` <br /> |
| `needle` | `CharSequence` <br /> |
| `start`  | `int` <br />          |

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### indexOf

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

<br />

|           Parameters            ||
|----------|-----------------------|
| `s`      | `CharSequence` <br /> |
| `needle` | `CharSequence` <br /> |

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### indexOf

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

<br />

|           Parameters           ||
|---------|-----------------------|
| `s`     | `CharSequence` <br /> |
| `ch`    | `char` <br />         |
| `start` | `int` <br />          |

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### indexOf

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

<br />

|         Parameters          ||
|------|-----------------------|
| `s`  | `CharSequence` <br /> |
| `ch` | `char` <br />         |

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### isDigitsOnly

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean isDigitsOnly (CharSequence str)
```

Returns whether the given CharSequence contains only digits.

<br />

|          Parameters          ||
|-------|-----------------------|
| `str` | `CharSequence` <br /> |

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### isEmpty

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean isEmpty (CharSequence str)
```

Returns true if the string is null or 0-length.

<br />

|                                    Parameters                                    ||
|-------|---------------------------------------------------------------------------|
| `str` | `CharSequence`: the string to be examined This value may be`null`. <br /> |

|                       Returns                        ||
|-----------|-------------------------------------------|
| `boolean` | true if str is null or zero length <br /> |

### isGraphic

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean isGraphic (CharSequence str)
```

Returns whether the given CharSequence contains any printable characters.

<br />

|          Parameters          ||
|-------|-----------------------|
| `str` | `CharSequence` <br /> |

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### isGraphic

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Deprecated in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static boolean isGraphic (char c)
```

<br />

**This method was deprecated in API level 24.**   
Use[isGraphic(java.lang.CharSequence)](https://developer.android.com/reference/android/text/TextUtils#isGraphic(java.lang.CharSequence))instead.

Returns whether this character is a printable character. This does not support non-BMP characters and should not be used.

<br />

|     Parameters     ||
|-----|---------------|
| `c` | `char` <br /> |

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### join

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static String join (CharSequence delimiter, 
                Iterable<T> tokens)
```

Returns a string containing the tokens joined by delimiters.

<br />

|                                                                                                                      Parameters                                                                                                                      ||
|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `delimiter` | `CharSequence`: a CharSequence that will be inserted between the tokens. If null, the string "null" will be used as the delimiter. <br />                                                                                               |
| `tokens`    | `Iterable`: 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. <br /> |

|                                  Returns                                   ||
|--------------------------------------------------------------------|--------|
| [String](https://developer.android.com/reference/java/lang/String) | <br /> |

### join

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static String join (CharSequence delimiter, 
                Object[] tokens)
```

Returns a string containing the tokens joined by delimiters.

<br />

|                                                                                                                         Parameters                                                                                                                          ||
|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `delimiter` | `CharSequence`: a CharSequence that will be inserted between the tokens. If null, the string "null" will be used as the delimiter. <br />                                                                                                      |
| `tokens`    | `Object`: 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. <br /> |

|                                  Returns                                   ||
|--------------------------------------------------------------------|--------|
| [String](https://developer.android.com/reference/java/lang/String) | <br /> |

### lastIndexOf

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

<br />

|          Parameters           ||
|--------|-----------------------|
| `s`    | `CharSequence` <br /> |
| `ch`   | `char` <br />         |
| `last` | `int` <br />          |

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### lastIndexOf

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

<br />

|         Parameters          ||
|------|-----------------------|
| `s`  | `CharSequence` <br /> |
| `ch` | `char` <br />         |

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### lastIndexOf

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

<br />

|           Parameters           ||
|---------|-----------------------|
| `s`     | `CharSequence` <br /> |
| `ch`    | `char` <br />         |
| `start` | `int` <br />          |
| `last`  | `int` <br />          |

|    Returns    ||
|-------|--------|
| `int` | <br /> |

### listEllipsize

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static CharSequence listEllipsize (Context context, 
                List<CharSequence> elements, 
                String separator, 
                TextPaint paint, 
                float avail, 
                int moreId)
```

Formats a list of CharSequences by repeatedly inserting the separator between them, but stopping when the resulting sequence is too wide for the specified width. This method actually tries to fit the maximum number of elements. So if`"A, 11 more"
fits`,`"A, B, 10 more"`doesn't fit, but`"A, B, C, 9 more"`fits again (due to the glyphs for the digits being very wide, for example), it returns`"A, B, C, 9 more"`. Because of this, this method may be inefficient for very long lists. Note that the elements of the returned value, as well as the string for`moreId`, will be bidi-wrapped using[BidiFormatter.unicodeWrap](https://developer.android.com/reference/android/text/BidiFormatter#unicodeWrap(java.lang.CharSequence))based on the locale of the input Context. If the input`Context`is null, the default BidiFormatter from[BidiFormatter.getInstance()](https://developer.android.com/reference/android/text/BidiFormatter#getInstance())will be used.

<br />

|                                                                 Parameters                                                                 ||
|-------------|-------------------------------------------------------------------------------------------------------------------------------|
| `context`   | `Context`: the`Context`to get the`moreId`resource from. If`null`, an ellipsis (U+2026) would be used for`moreId`. <br />      |
| `elements`  | `List`: the list to format This value may be`null`. <br />                                                                    |
| `separator` | `String`: a separator, such as`", "`This value cannot be`null`. <br />                                                        |
| `paint`     | `TextPaint`: the Paint with which to measure the text This value cannot be`null`. <br />                                      |
| `avail`     | `float`: the horizontal width available for the text (in pixels) Value is 0.0f or greater <br />                              |
| `moreId`    | `int`: the resource ID for the pluralized string to insert at the end of sequence when some of the elements don't fit. <br /> |

|                                                                                                      Returns                                                                                                       ||
|--------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | the formatted CharSequence. If even the shortest sequence (e.g.`"A, 11 more"`) doesn't fit, it will return an empty string. <br /> |

### makeSafeForPresentation

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static CharSequence makeSafeForPresentation (String unclean, 
                int maxCharactersToConsider, 
                float ellipsizeDip, 
                int flags)
```

Remove html, remove bad characters, and truncate string.

This method is meant to remove common mistakes and nefarious formatting from strings that were loaded from untrusted sources (such as other packages).

This method first[treats the string like HTML](https://developer.android.com/reference/android/text/Html#fromHtml(java.lang.String))and then ...

- Removes new lines or truncates at first new line
- Trims the white-space off the end
- Truncates the string

... if specified.

<br />

<br />

|                                                                                                                                                                                                                                                                                                                                                                                                                                Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                 ||
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `unclean`                 | `String`: The input string This value cannot be`null`. <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `maxCharactersToConsider` | `int`: The maximum number of characters of`unclean`to consider from the input string.`0`disables this feature. Value is 0 or greater <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `ellipsizeDip`            | `float`: Assuming maximum length of the string (in dip), assuming font size 42. This is roughly 50 characters for`ellipsizeDip == 1000`. Usually ellipsizing should be left to the view showing the string. If a string is used as an input to another string, it might be useful to control the length of the input string though.`0`disables this feature. Value is 0.0f or greater <br />                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `flags`                   | `int`: Flags controlling cleaning behavior (Can be[SAFE_STRING_FLAG_TRIM](https://developer.android.com/reference/android/text/TextUtils#SAFE_STRING_FLAG_TRIM),[SAFE_STRING_FLAG_SINGLE_LINE](https://developer.android.com/reference/android/text/TextUtils#SAFE_STRING_FLAG_SINGLE_LINE), and[SAFE_STRING_FLAG_FIRST_LINE](https://developer.android.com/reference/android/text/TextUtils#SAFE_STRING_FLAG_FIRST_LINE)) Value is either`0`or a combination of[SAFE_STRING_FLAG_TRIM](https://developer.android.com/reference/android/text/TextUtils#SAFE_STRING_FLAG_TRIM),[SAFE_STRING_FLAG_SINGLE_LINE](https://developer.android.com/reference/android/text/TextUtils#SAFE_STRING_FLAG_SINGLE_LINE), and[SAFE_STRING_FLAG_FIRST_LINE](https://developer.android.com/reference/android/text/TextUtils#SAFE_STRING_FLAG_FIRST_LINE) <br /> |

|                                                                Returns                                                                ||
|--------------------------------------------------------------------------------|-------------------------------------------------------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | The cleaned string This value cannot be`null`. <br /> |

### regionMatches

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

<br />

<br />

|            Parameters            ||
|-----------|-----------------------|
| `one`     | `CharSequence` <br /> |
| `toffset` | `int` <br />          |
| `two`     | `CharSequence` <br /> |
| `ooffset` | `int` <br />          |
| `len`     | `int` <br />          |

|      Returns      ||
|-----------|--------|
| `boolean` | <br /> |

### replace

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static CharSequence replace (CharSequence template, 
                String[] sources, 
                CharSequence[] destinations)
```

Return a new CharSequence in which each of the source strings is replaced by the corresponding element of the destinations.

<br />

|              Parameters               ||
|----------------|-----------------------|
| `template`     | `CharSequence` <br /> |
| `sources`      | `String` <br />       |
| `destinations` | `CharSequence` <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | <br /> |

### split

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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 on whether your app[targets
an SDK version](https://developer.android.com/reference/android/content/pm/ApplicationInfo#targetSdkVersion)`<= 28`; see[Pattern.split(CharSequence, int)](https://developer.android.com/reference/java/util/regex/Pattern#split(java.lang.CharSequence,%20int)).

<br />

|                          Parameters                          ||
|-----------|---------------------------------------------------|
| `text`    | `String`: the string to split <br />              |
| `pattern` | `Pattern`: the regular expression to match <br /> |

|                                                                  Returns                                                                   ||
|----------------------------------------------------------------------|----------------------------------------------------------------------|
| [String[]](https://developer.android.com/reference/java/lang/String) | an array of strings. The array will be empty if text is empty <br /> |

|                                                            Throws                                                             ||
|------------------------------------------------------------------------------------------------|-------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if expression or text is null |

### split

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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[targets an SDK version](https://developer.android.com/reference/android/content/pm/ApplicationInfo#targetSdkVersion)`<= 28`; see[Pattern.split(CharSequence, int)](https://developer.android.com/reference/java/util/regex/Pattern#split(java.lang.CharSequence,%20int)).

<br />

|                           Parameters                           ||
|--------------|--------------------------------------------------|
| `text`       | `String`: the string to split <br />             |
| `expression` | `String`: the regular expression to match <br /> |

|                                                                  Returns                                                                   ||
|----------------------------------------------------------------------|----------------------------------------------------------------------|
| [String[]](https://developer.android.com/reference/java/lang/String) | an array of strings. The array will be empty if text is empty <br /> |

|                                                            Throws                                                             ||
|------------------------------------------------------------------------------------------------|-------------------------------|
| [NullPointerException](https://developer.android.com/reference/java/lang/NullPointerException) | if expression or text is null |

### stringOrSpannedString

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static CharSequence stringOrSpannedString (CharSequence source)
```

<br />

<br />

|           Parameters            ||
|----------|-----------------------|
| `source` | `CharSequence` <br /> |

|                                        Returns                                         ||
|--------------------------------------------------------------------------------|--------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | <br /> |

### substring

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
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](https://developer.android.com/reference/java/lang/CharSequence#subSequence(int,%20int))in that it does not preserve any style runs in the source sequence, allowing a more efficient implementation.

<br />

|           Parameters            ||
|----------|-----------------------|
| `source` | `CharSequence` <br /> |
| `start`  | `int` <br />          |
| `end`    | `int` <br />          |

|                                  Returns                                   ||
|--------------------------------------------------------------------|--------|
| [String](https://developer.android.com/reference/java/lang/String) | <br /> |

### writeToParcel

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static void writeToParcel (CharSequence cs, 
                Parcel p, 
                int parcelableFlags)
```

Flatten a CharSequence and whatever styles can be copied across processes into the parcel.

<br />

|                             Parameters                             ||
|-------------------|-------------------------------------------------|
| `cs`              | `CharSequence`: This value may be`null`. <br /> |
| `p`               | `Parcel`: This value cannot be`null`. <br />    |
| `parcelableFlags` | `int` <br />                                    |