字串常用方法

2021-09-20 19:29:43 字數 1851 閱讀 7020

字串常用方法

method

描述charat()

返回指定索引位置的字元

charcodeat()

返回指定索引位置字元的 unicode 值

concat()

連線兩個或多個字串,返回連線後的字串

fromcharcode()

將字元轉換為 unicode 值

indexof()

返回字串中檢索指定字元第一次出現的位置

lastindexof()

返回字串中檢索指定字元最後一次出現的位置

localecompare()

用本地特定的順序來比較兩個字串

match()

找到乙個或多個正規表示式的匹配

replace()

替換與正規表示式匹配的子串

search()

檢索與正規表示式相匹配的值

slice()

提取字串的片斷,並在新的字串中返回被提取的部分

split()

把字串分割為子字串陣列

substr()

從起始索引號提取字串中指定數目的字元

substring()

提取字串中兩個指定的索引號之間的字元

tolocalelowercase()

根據主機的語言環境把字串轉換為小寫,只有幾種語言(如土耳其語)具有地方特有的大小寫對映

tolocaleuppercase()

根據主機的語言環境把字串轉換為大寫,只有幾種語言(如土耳其語)具有地方特有的大小寫對映

tolowercase()

把字串轉換為小寫

tostring()

返回字串物件值

touppercase()

把字串轉換為大寫

trim()

移除字串首尾空白

valueof()

返回某個字串物件的原始值

例子:1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

字串常用方法

字串常用方法 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 判斷型別 9 方法說明 string.isspace 如果 string 中只包含空格,則返回 true string.isalnum 如果 string 至少有乙個字元並且所有字元都是字母或數字則返回 true string.isalpha 如果 string 至少有乙個字元並且所有字元都是字...

字串常用方法

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