android TextUtils工具类的用法

方法摘要

static CharSequence

返回一个字符序列

 

 

commaEllipsize(CharSequence text,TextPaint p, float avail,String oneMore,String more)           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".

转换一个以逗号为分隔的字符序列。比如把"Andy,Bob,Charles,David"以逗号相隔的字符序列太长,,而把它转换成指定的长度的字符序列,比如"Andy,Bob,2 more";省略掉了两个逗号之后的内容

 

static CharSequence

同上

concat(CharSequence... text)           Returns a CharSequence concatenating the specified CharSequences, retaining their spans if any.

返回一个连接指定字符序列的字符序列,保留它们之间的任何间隔宽度。

static void

返回为空

copySpansFrom(Spanned source, int start, int end, Class kind,Spannable dest, int destoff)

从一个间隔宽度源中复制间隔宽度。

static void

同上

dumpSpans(CharSequence cs,Printer printer,String prefix)           Debugging tool to print the spans in a CharSequence.

调试工具打印一个字符序列中间隔宽度。

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.

返回一个原始的文本。如果这个文本适合指定的宽度及给定的属性(指定的画笔);否则,如果它不适合,一个截断的包括省略字符的复制会被添加到指定的边缘或者中心。

static CharSequence

同上

 

ellipsize(CharSequence text,TextPaint p, 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.

同上,同上面的方法的有不同之处

static boolean

返回一个布尔值

equals(CharSequence a,CharSequence b)           Returns true if a and b are equal, including if they are both null.

如果字符序列a和b相等(包括如果字符序列a和b都为空)就返回true

static CharSequence返回一个字符序列

expandTemplate(CharSequence template,CharSequence... values)           Replace instances of "^1", "^2", etc. in thetemplate CharSequence with the correspondingvalues. "^^" is used to produce a single caret in the output.

代替"^1"和 "^2"的实例等等。这个模板字符序列与它相对应的值,用"^^"这个产生一个单一的插入符号。

static int

返回一个整型值

getCapsMode(CharSequence cs, int off, int reqModes)           Determine what caps mode should be in effect at the current offset in the text.

指定上限模式在文本当中实际应该在当前抵消的内容

static void

返回为空

getChars(CharSequence s, int start, int end, char[] dest, int destoff) 按要求获取一些字符          

static int

返回整型值

getOffsetAfter(CharSequence text, int offset)

获取文本之后的偏移量          

static int

同上

getOffsetBefore(CharSequence text, int offset) 获取文本之前的偏移量         

static CharSequence

返回字符序列

getReverse(CharSequence source, int start, int end) 获取字符源的反向序列         

static int

返回整型值

getTrimmedLength(CharSequence s)           Returns the length that the specified CharSequence would have if spaces and control characters were trimmed from the start and end, as byString.trim().

获取去掉字符序列头尾空格整理后的字符序列长度。如果你String.trim()方法的作用一样把该字符序列头尾的空格已经去掉并已经整理,就返回指定的字符序列的长度。

static String

返回一个静态的字符串

htmlEncode(String s)           Html-encode the string.

把这个字符串进行Html编码,并返回编码后的字符串

static int

返回一个静态的整型值

indexOf(CharSequence s, char ch)

返回字符ch在该字符序列中第一次出现的位置          

static int

同上

indexOf(CharSequence s, char ch, int start)

返回在字符序列中指定的位置开始找到字符ch出现第一次的位置

static int

同上

indexOf(CharSequence s, char ch, int start, int end)

返回在字符序列中指定的一段字符序列中字符ch出现的第一次的位置          

static int

同上

indexOf(CharSequence s,CharSequence needle) 返回指定的字符序列needle在字符序列s中第一次出现的位置

static int

同上

indexOf(CharSequence s,CharSequence needle, int start) 返回从字符序列中s指定的位置开始字符序列needle第一次出现的位置         

static int

同上

indexOf(CharSequence s,CharSequence needle, int start, int end)

返回在字符序列s指定的一段中字符序列needle第一次出现的位置           

static boolean

返回静态的布尔值

isDigitsOnly(CharSequence str)           Returns whether the given CharSequence contains only digits.

判断给定的字符序列是否只包含数字。返回是否给定的字符序列只包含数字的布尔值。

static boolean

同上

isEmpty(CharSequence str)           Returns true if the string is null or 0-length.

判断给定的字符序列是否为空。如果字符串为空或者它的长度为0返回true

static boolean

同上

isGraphic(char c)           Returns whether this character is a printable character.

判断给定的字符c是否是图形。返回给定的字符c是否是可打印的字符的布尔值。

static boolean

同上

isGraphic(CharSequence str)           Returns whether the given CharSequence contains any printable characters.

判断给定的字符序列str是否是图形。返回给定的字符序列是否包含任何可打印的字符的布尔值。

static String

返回静态的字符串

join(CharSequence delimiter,Iterable tokens)           Returns a string containing the tokens joined by delimiters.

让指定的迭代器加入到指定的分隔符序列中,组成一个字符串,并返回这个字符串。返回一个包含指定的迭代器加入到指定的分隔符字符序列的字符串。

static String

同上

join(CharSequence delimiter,Object[] tokens)           Returns a string containing the tokens joined by delimiters.

让指定的符号组加入到分隔符字符序列中并组成一个字符串。返回这个字符串。

static int

返回整型值

lastIndexOf(CharSequence s, char ch)

返回指定字符ch在指定的字符序列s中最后一个位置的值。           

static int

同上

lastIndexOf(CharSequence s, char ch, int last) 返回指定字符ch在指定的字符序列s中到指定的末尾处最后一个位置的值。         

static int

同上

lastIndexOf(CharSequence s, char ch, int start, int last) 返回指定字符c在指定的字符序列s中指定的一段中最后一个位置的值。         

static boolean

返回静态的布尔值

regionMatches(CharSequence one, int toffset,CharSequence two, int ooffset, int len)

返回指定的字符序列one从toffset开始和指定的字符序列two 从ooffset开始比较指定长度的字符序列的布尔值。如果相同就返回true.如果不同就返回false。(个人觉得会区分大小写)       

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.

返回一个新的字符序列:这个源字符串被目标字符序列组中对应的元素所代替而产生的一个新字符序列。

static String[]

返回静态的字符组

split(String text,Pattern pattern)           Splits a string on a pattern.

返回用指定的样式来分隔这个字符串而形成的那个新的字符串。

static String[]

同上

split(String text,String expression)           String.split() returns [''] when the string to be split is empty.

返回用指定表达式来分隔指定的字符串而产生的新的字符串。当字符串被分隔后是空的就返回['']

static CharSequence

返回一个静态的字符序列

stringOrSpannedString(CharSequence source) 

返回指定字符序列源的字符串或额外的字符串。     

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 void

返回静态空

writeToParcel(CharSequence cs,Parcel p, int parcelableFlags)           Flatten a CharSequence and whatever styles can be copied across processes into the parcel.

拼合一个字符序列并且无论何种样式都能跨进程被复制

 

posted @ 2013-06-14 16:20  公孙 轩辕  阅读(6105)  评论(0编辑  收藏  举报