之前在代码里经常遇到这个类,没太关注。今天去官方文档看了下,意外收获:原来它包含很多与Java的String类功能相同或相近的方法。但是也有很多貌似String没有的方法。
static boolean |
equals(
CharSequence a,
CharSequence b)
Returns true if a and b are equal, including if they are both null.
|
static int | indexOf( CharSequence s, char ch) |
static boolean |
isEmpty(
CharSequence str)
Returns true if the string is null or 0-length.
|
static int | lastIndexOf( CharSequence s, char ch) |
static String[] |
split(
String text,
String expression)
String.split() returns [''] when the string to be split is empty.
|
static String |
substring(
CharSequence source, int start, int end)
Create a new String object containing the given range of characters from the source string.
|
static 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.
|
一些“貌似”是String类没有的方法,也可能我之前没遇到过:
static void |
writeToParcel(
CharSequence cs,
Parcel p, int parcelableFlags)
Flatten a CharSequence and whatever styles can be copied across processes into the parcel.
|
public static CharSequence concat (CharSequence... text)
Added in
API level 1
Returns a CharSequence concatenating the specified CharSequences, retaining their spans if any.
Parameters | |
---|---|
text | CharSequence |
Returns | |
---|---|
CharSequence |
public static void dumpSpans (CharSequence cs, Printer printer, String prefix)
Added in
API level 3
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.
Parameters | |
---|---|
cs | CharSequence |
printer | Printer |
prefix | String |