Java的基礎字串的一些方法

2021-08-09 01:47:27 字數 3775 閱讀 9159

public class stringdemo

} 定義的的字串

1 char charat(int index)

返回指定索引處的 char 值。

2 int compareto(object o)

把這個字串和另乙個物件比較。

3 int compareto(string anotherstring)

按字典順序比較兩個字串。

4 int comparetoignorecase(string str)

按字典順序比較兩個字串,不考慮大小寫。

5 string concat(string str)

將指定字串連線到此字串的結尾。

6 boolean contentequals(stringbuffer sb)

當且僅當字串與指定的stringbutter有相同順序的字元時候返回真。

7 static string copyvalueof(char data)

返回指定陣列中表示該字串行的 string。

8 static string copyvalueof(char data, int offset, int count)

返回指定陣列中表示該字串行的 string。

9 boolean endswith(string suffix)

測試此字串是否以指定的字尾結束。

10 boolean equals(object anobject)

將此字串與指定的物件比較。

11 boolean equalsignorecase(string anotherstring)

將此 string 與另乙個 string 比較,不考慮大小寫。

12 byte getbytes()

使用平台的預設字符集將此 string 編碼為 byte 序列,並將結果儲存到乙個新的 byte 陣列中。

13 byte getbytes(string charsetname)

使用指定的字符集將此 string 編碼為 byte 序列,並將結果儲存到乙個新的 byte 陣列中。

14 void getchars(int srcbegin, int srcend, char dst, int dstbegin)

將字元從此字串複製到目標字元陣列。

15 int hashcode()

返回此字串的雜湊碼。

16 int indexof(int ch)

返回指定字元在此字串中第一次出現處的索引。

17 int indexof(int ch, int fromindex)

返回在此字串中第一次出現指定字元處的索引,從指定的索引開始搜尋。

18 int indexof(string str)

返回指定子字串在此字串中第一次出現處的索引。

19 int indexof(string str, int fromindex)

返回指定子字串在此字串中第一次出現處的索引,從指定的索引開始。

20 string intern()

返回字串物件的規範化表示形式。

21 int lastindexof(int ch)

返回指定字元在此字串中最後一次出現處的索引。

22 int lastindexof(int ch, int fromindex)

返回指定字元在此字串中最後一次出現處的索引,從指定的索引處開始進行反向搜尋。

23 int lastindexof(string str)

返回指定子字串在此字串中最右邊出現處的索引。

24 int lastindexof(string str, int fromindex)

返回指定子字串在此字串中最後一次出現處的索引,從指定的索引開始反向搜尋。

25 int length()

返回此字串的長度。

26 boolean matches(string regex)

告知此字串是否匹配給定的正規表示式。

27 boolean regionmatches(boolean ignorecase, int toffset, string other, int ooffset, int len)

測試兩個字串區域是否相等。

28 boolean regionmatches(int toffset, string other, int ooffset, int len)

測試兩個字串區域是否相等。

29 string replace(char oldchar, char newchar)

返回乙個新的字串,它是通過用 newchar 替換此字串中出現的所有 oldchar 得到的。

30 string replaceall(string regex, string replacement

使用給定的 replacement 替換此字串所有匹配給定的正規表示式的子字串。

31 string replacefirst(string regex, string replacement)

使用給定的 replacement 替換此字串匹配給定的正規表示式的第乙個子字串。

32 string split(string regex)

根據給定正規表示式的匹配拆分此字串。

33 string split(string regex, int limit)

根據匹配給定的正規表示式來拆分此字串。

34 boolean startswith(string prefix)

測試此字串是否以指定的字首開始。

35 boolean startswith(string prefix, int toffset)

測試此字串從指定索引開始的子字串是否以指定字首開始。

36 charsequence subsequence(int beginindex, int endindex)

返回乙個新的字串行,它是此序列的乙個子串行。

37 string substring(int beginindex)

返回乙個新的字串,它是此字串的乙個子字串。

38 string substring(int beginindex, int endindex)

返回乙個新字串,它是此字串的乙個子字串。

39 char tochararray()

將此字串轉換為乙個新的字元陣列。

40 string tolowercase()

使用預設語言環境的規則將此 string 中的所有字元都轉換為小寫。

41 string tolowercase(locale locale)

使用給定 locale 的規則將此 string 中的所有字元都轉換為小寫。

42 string tostring()

返回此物件本身(它已經是乙個字串!)。

43 string touppercase()

使用預設語言環境的規則將此 string 中的所有字元都轉換為大寫。

44 string touppercase(locale locale)

使用給定 locale 的規則將此 string 中的所有字元都轉換為大寫。

45 string trim()

返回字串的副本,忽略前導空白和尾部空白。

46 static string valueof(primitive data type x)

返回給定data type型別x引數的字串表示形式。

JAVA基礎 關於String字串的一些方法

字串的複製 字串的比較 compareto equalsignorecase 查詢字串中是否包含某個字元 indexof 字串的擷取 substring 字串替換 replace 判斷某字串是否以指定字串開始或結尾 startswith endswith 轉換字串大小寫 touppercase to...

字串的一些常用方法

字串的其他常用方法 1.字串的轉換函式 nsstring str1 111add333 int a1 str1 intvalue float b1 str1 floatvalue double c1 str1 doublevalue nslog d a1 2.字串大小寫轉換函式 nsstring s...

關於字串的一些方法

substring public string substring int beginindex 返回乙個新的字串,它是此字串的乙個子字串。該子字串始於指定索引處的字元,一直到此字串末尾。example string str abcdefg str str.substring 2 system.ou...