JS 字符串

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title></title>
 6     </head>
 7     <body>
 8     </body>
 9     
10     <script type="text/javascript">
11         var stringValue = "guoxiaomin";
12         // charAt() 取出下标为5的单字符
13         var subChar = stringValue.charAt(5);
14         console.log(subChar);
15         
16 
17 
18 
19         // charCodeAt() 取出下标为5的字符的 ascii 码
20         var subChar = stringValue.charCodeAt(5);
21         console.log(subChar);
22         // 上述取值需要注意越界问题,参数范围:0-字符串长度-1
23         
24 
25         
26         // []方法,可以去到字母中的第4个字
27         console.log(stringValue[3]); 
28 
29         // 4是个数。。从第4个之前都不要,取第四个字母之后的数字
30         var sub1 =     stringValue.substring(4); 
31         console.log(sub1);
32         
33 
34         // 俩个参数的时候
35         // substring
36         var sub1 = stringValue.substring(1,6);
37         console.log(sub1);
38 
39         
40         // slice
41         var sub2 = stringValue.slice(1,6);
42         console.log(sub2);
43 
44 
45         // substr  这个6代表的是长度
46         var sub3 = stringValue.substr(1,6);
47         console.log(sub3);
48     
49         var bigChar = "GXM";
50         console.log(bigChar);
51         
52         // 转化小写toLowerCase有返回值,会生成新的小写字符串
53         bigChar =  bigChar.toLowerCase();    
54         console.log(bigChar);
55         
56         // 小写再变回大写
57         bigChar =  bigChar.toUpperCase();
58         console.log(bigChar);
59         
60         
61     </script>
62 </html>
原文地址:https://www.cnblogs.com/PowellZhao/p/5576521.html