字串常用方法

2021-08-19 21:16:51 字數 1406 閱讀 6036

/*

字串常用方法

*/public class ****3//abc

//5 int indexof(string str);

//輸出字串2在字串1中的下標

system.out.println("hello crl".endswith("crl"));//6

//6int indexof(string str,int fromindex);

//在字串1中從x下標開始尋找字串2

//7int lastindexof(string str);

//搜尋字串2在字串1最後出現的下標

//8int lastindexof(string str,int fromindex);

//在字串1的x下標開始搜尋字串2

//9int length();   陣列是length屬性,string是型別方法

//衡量字串的長度

//10

string replaceall(string s1,string s2);

//引用字串裡的所有字串1用字串2代替

//11

string spilt(string s);

//把引用字串用字串s進行分割之後的各部分儲存在string型別陣列裡面

//12

boolean starwith(string s);

//判斷字串1是否以字串2開始

//13

string substring(int begin);

//把字串1從x下標開始擷取

//14

string substring(int beginindex,int endindex);

//把字串1從指定下標開始擷取到截至下標的前一位

//包括前面不包括後面

//15

char tochararray();

// 把字串用乙個字元陣列進行接收

//16

touppercase();

把字母轉換成大寫

//17

tolowercaese();

把字母轉換成小寫

//18

string trim();

//把字串前面和後面的空格去掉

//string valueof(object o) 

//後面的括號可以加所有型別,最後給你轉換成字串型別

object o=null;

system.out.println(o);

//不會空指標異常,實際上等於下式

//因為已經對o進行了處理

system.out.println(string.valueof(0));

//會報空指標異常

system.out.println(o.tostring());}}

字串常用方法

1 判斷型別 9 方法說明 string.isspace 如果 string 中只包含空格,則返回 true string.isalnum 如果 string 至少有乙個字元並且所有字元都是字母或數字則返回 true string.isalpha 如果 string 至少有乙個字元並且所有字元都是字...

字串常用方法

字串常用方法 method 描述charat 返回指定索引位置的字元 charcodeat 返回指定索引位置字元的 unicode 值 concat 連線兩個或多個字串,返回連線後的字串 fromcharcode 將字元轉換為 unicode 值 indexof 返回字串中檢索指定字元第一次出現的位...

字串常用方法

js字串常用方法總結 1 tolowercase 把字串轉為小寫,返回新的字串。var str hello world var str1 str.tolowercase console.log str hello world console.log str1 hello world 2 touppe...