string常用方法

2022-09-16 05:00:10 字數 591 閱讀 5396

charat():返回char指定索引處的值

compareto():比較unicode值,大返回正值,小返回負值,相等返回0

concat:連線字串,返回新字串

contains:判斷是否包含指定字元,返回值為boolean

equals:將字串與指定物件比較,若值相等返回true

hashcode:返回雜湊值

indexof:返回指定字元第一次出現的索引

split(string regex):按指定字串進行分割,返回字串陣列

split(string r,int limit):limit 該引數用於控制模式匹配使用的次數,可以影響到陣列的長度.

limit>0:

模式匹配將被最多應用n-1次。

2.limit<0:

模式匹配將應用盡可能多的次數,而且陣列的長度是任何長度。

3.lilmit=0:

模式匹配將被應用盡可能多的次數,陣列可以是任何長度,並且結尾空字串將被丟棄。

substring(int beginindex):

substring(int beginindex, int endindex):左開右閉

String常用方法

1,startswith判斷是否以某字串開始 2,endswith判斷是否以某字串結尾 3,contains判斷是否包含另乙個字串 4,substring取出指定位置的字串 5,charat找到指定位置的字元 6,indexof正向找到指定字元的位置 7,lastindexof反向找到指定字元的位置...

string 常用方法

例項化方法建立字串 instancetype initwithstring nsstring astring instancetype initwithformat nsstring format,instancetype initwithutf8string const char bytes 類方...

String常用方法

public class teststring string str hello string的方法 1 跟字元陣列有關的方法 物件的長度 char array str.tochararray 把string物件轉換成char陣列 根據下標得到string物件該下標位置的字元 l 得到某個字元在st...