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.

拼合一個字符序列並且無論何種樣式都能跨進程被復制

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM