• JavaScript的String对象相关方法


     

     

     

     

     

     

     

     

     

     

     

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <script type="text/javascript">
            /*var str="hello world";
            // console.log(str[1]);
            console.log(str.charAt(4));
            //检测@在email中出现的位置
            var email="marry.mail@sohu.com";
            console.log(email.indexOf("o"));
            console.log(email.lastIndexOf("."));*/
            var str="hello world";
            //截取orl
            /*console.log(str.slice(7,10));
            console.log(str.slice(1));
            //str.slice(8)    //str.slice(4,9)
            console.log(str.slice(-7,-2));*/
            /*console.log(str.substring(-7,5));//(0,5)
            console.log(str.substring(2,-5));//(0,2)*/
            //str.substring(6,9)
            console.log(str.substr(6,3));
            console.log(str.substr(-5,4));//(6,4)
            console.log(str.substr(3,-4));
            </script>
    </body>
    </html>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <script type="text/javascript">
            //获取扩展名
            var url="http://baidu.com/index.txt";
            function getFileFormat(url){
                //获取.在url中出现的位置
                var pos=url.lastIndexOf(".");
                return url.substr(pos);
            }
            var formatName=getFileFormat(url);
            var picFormat=getFileFormat("1231434.jpg");
            console.log(formatName);
            console.log(picFormat);
        </script>
    </body>
    </html> 
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <script type="text/javascript">
            var str='welcome-to-beijing';
            //使用split将str转换为数组
            var arr=str.split("-");
            var date='2016/05/05';
            //["welcome","to","bejing"]
            var dateArr=date.split("/");
            console.log(arr);
            console.log(dateArr);
            //替换
            var tel='010-62971268,400-100-9098,010-86789889';
            var newTel=tel.replace(',',"  ");
            console.log(tel);
            console.log(newTel);
        </script>
    </body>
    </html>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <script type="text/javascript">
            /*var str="hello world";
            var upper=str.charAt(6).toUpperCase();
            // console.log(str.toUpperCase());
            var str2="WELCOME";
            console.log(str2.toLowerCase());*/
            //border-left-color borderLeftColor    //驼峰形式
            //margin-bottom
            function camelback(str){
                //通过-这个分隔符将str拆分成数组
                var arr=str.split("-"),newStr=arr[0];
                //console.log(arr);//["border","left","color"]
                //newStr="border";
                for(var i=1,len=arr.length;i<len;i++){
                    var word=arr[i];
                    //将每一个单词的首字母转换为大写,连接剩余字符
                    newStr+=word.charAt(0).toUpperCase()+word.substr(1);
                    //console.log(newStr);    //Left Color L C
                    //newStr=borderLeftColor
                }
                return newStr;
            }
            //var camelFormat=camelback("border-left-color");
            var camelFormat=camelback("get-element-by-id");
            console.log(camelFormat);
        </script>
    </body>
    </html>
  • 相关阅读:
    【转贴】Render to Texture(渲染到纹理)
    【转贴】EffectFramework
    真正的电脑高手
    【ZT】剑道与编程之道
    【转贴】DXUT 框架入门 2
    【转贴】DXUT 框架函数介绍
    第四章 治病法要(1)
    第一章 略说中医的学习与研究(5)
    第二章 伤寒之意义(2)
    第一章 略说中医的学习与研究(4)
  • 原文地址:https://www.cnblogs.com/zengyu1234/p/15782739.html
Copyright © 2020-2023  润新知