字符串工具类TextUtils

之前在代码里经常遇到这个类,没太关注。今天去官方文档看了下,意外收获:原来它包含很多与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








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值