2016年11月23日,星期三


        1.增加型:

       String.concat:将数据连接到字符串末尾,原字符串不变,返回新的字符串。

         表示:

          <script>

              var varString = "abcdef";

              var b = varString.concat("123");

              document.write(b);

          </script>

        2.修改型:

           String.toUpperCase:把整个字符串改成大写。

           表示:

            <script>

                var varString = "abCdef";

                var b = varString.toUpperCase();

                document.write(b);

            </script>

          

            String.toLowerCase:把整个字符串改成小写。

            表示:

             <script>

                var varString = "ABCdef";

                var b = varString.toLowerCase();

                document.write(b);

             </script>

                

           3.查找项:

          String.indexOf:查找指定的字符第一次出现的位置varString.indexOf               ("查找指定的字符",开始查找的位置)

              表示:

                <script>

                    var varString = "我爱你Cd,eCf";

                    var b = varString.indexOf("C", 4);

                    var c = String.fromCharCode();

                    document.write(b);

                </script>

                   

                  String.length:求字符串的长度。

                 表示:

                    <script>

                        var varString = "CdeCf";

                        var b = varString.length;

                        document.write(b);

                    </script> 

                Script.Slice:截取字符串。

                表示:

                    <script>

                        var varString = "CdeCf";

                        varString.slice(开始的下标,结束的下标)

                        var b = varString.slice(1,3);

                        document.write(b);

                    </script> 

                 String.toString:将其他类型的变量转换成字符串

                 表示:

                    <script>

                        var varString = 123;

                        var c = varString.toString();

                        var b= c.substring(0);

                        document.write(b);

                    </script>