字串方法

2021-10-11 18:36:55 字數 1754 閱讀 9159

判斷子串是否存在

查詢子串位置

從給定位置往前找

判斷字串是否以子串開頭

判斷字串是否以子串結尾

public static void main

(string[

] args)

拆分字串

public static void main

(string[

] args)

system.out.

println

("**********==");

string[

] strings1 = str.

split

(" ",2

);//以空格拆分為兩組

for(string str3:strings1)

}

拆分字串

public static void main

(string[

] args)

system.out.

println

("*****==");

string[

] strings1 = str.

split

("5");

//給了沒有,不拆

for(string str2:strings1)

system.out.

println

("*****==");

string[

] strings2 = str.

split

("\\.");

//轉義字元,\\ 代表乙個 \ **義字元)

for(string str2:strings2)

system.out.

println

("*****==");

string[

] strings3 = str.

split

("\\\\");

//轉義字元

for(string str2:strings3)

}

拆分字串,拆分多次

public static void main

(string[

] args)

}

public static void main

(string[

] args)

}}

字串轉大小寫

public static void main

(string[

] args)

字串長度

public static void main

(string[

] args)

; system.out.

println

(array.length)

;//陣列長度是屬性 length

string string=""

;//空串

system.out.

println

(string

.isempty()

);//判斷是否為空串(長度是否為0),不能判斷空物件

string string2 = null;

//空物件

}

字串方法

find 方法可以在乙個較長的字串中查詢子字串,並返回子字串所在位置最左邊的索引。如果沒有找到則返回 1。hello,world.cold enough?find world 6 title hello,world.cold enough?title.find hello 0 title.find ...

字串方法

coding utf 8 字串也可以理解為乙個容器,也存在索引值,而字串中的每乙個字元可以理解為是一 個元素。1 len 獲取字串長度的方法 print 字串長度len len abcd 2 字串的取值 string abcdef r1 string 0 r2 string 1 print r1,r...

字串方法

字串方法 在這裡插入 片 定義乙個字串 var box 我的世界 返回指定位置的字串 box.charat 2 console.log box.charat 2 字串的長度 box.length console.log box.length 英文大小寫 var box2 holle 大寫 box2....