学习笔记之一字符串中的一些方法(字母大小写转换);(在一串字符中查找某个位置是什么字符)

有需要的可以看看,里面包括(字母大小写转换);(在一串字符中查找某个位置是什么字符);看到这,没有你要的就不要看了,免得浪费了你的时间了.

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title>选取一个字符</title>
 6     </head>
 7     <body>
 8         <!--字母大小写转换
 9             toLowerCase()转为小写和toUpperCase()转为大写
10         -->
11         
12         
13         <!--在一串字符中查找某个位置是什么字符
14             chart(参数);参数:所选字符在字符串中的索引位置
15             charCodeAt(参数);所选字符在字符串中的索引位置
16             charCodeAt返回该字符在Unicode字符集中十进制编码
17             fromCharCode(12,24,85,45);编码之间用逗号隔开,输出有编码对应的字母或者数字组成的字符创
18         -->
19     </body>
20     <script type="text/javascript">
21         function checkCharType (charToCheck) {
22             var returnValue="0";
23             var charCode=charToCheck.charCodeAt(0);
24             if (charCode>="A".charCodeAt(0)&&charCode<="Z".charCodeAt(0)) {
25                 returnValue="U";
26             }else if (charCode>="a".charCodeAt(0)&&charCode<="z".charCodeAt(0)) {
27                 returnValue="L";
28             }else if (charCode>="0".charCodeAt(0)&&charCode<="9".charCodeAt(0)) {                
29                 returnValue="N";
30             }
31             return returnValue;
32         }
33     </script>
34     <script type="text/javascript">
35         var myString=prompt("输入文本","hello word!");
36         switch (checkCharType(myString)){
37             case "U":
38                 document.write("第一个字符是大写");
39                 break;
40             case "L":
41                 document.write("第一个字符是小写");
42                 break;
43             case "N":
44                 document.write("第一个字符是数字");
45                 break;
46             default:
47                 document.write("第一个不是字符也不是数字")
48                 
49         }
50     </script>
51     <script type="text/javascript">
52         //fromCharCode()
53         document.write("<br>"+String.fromCharCode(65,66,67));
54         
55         
56         
57     </script>
58 </html>

 

posted @ 2016-10-27 19:57  流年之外天空蓝  阅读(909)  评论(0编辑  收藏  举报