• JS String对象


    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>String对象</title>
    </head>
    <body>
        <script>
            //构建String对象
            //赋值
            var str1 = "haol"
            //输出类型
            document.write(typeof(str1));
            document.write("<br/>")
            //输出属性:可以查看字符串的长度
            document.write(str1.length);
            document.write("<br/>")
            var str3 = "ABCDE"
            document.write(str3.toLowerCase()); //将字母转换成小写字母tolowerCase
            document.write("<br/>")
            var str4 = "abcdef"
            document.write(str4.toUpperCase()); //将字母转换成大写字母toUpperCase
            document.write("<br/>")
            //截取字符串,字符串从0开始编号
            document.write(str4.substr(1, 5));
            document.write("<br/>");
            //如果截取位为负数  则从字符串尾部开始
            document.write(str4.substr(-2));
            document.write("<br/>")
            //如果截取位只有一个值,那么就会从当前值往后截取
            document.write(str4.substr(2))
            document.write("<br/>")
            document.write(str4.substring(0, 4)) //substring 包含起始位,不包含结束位
            //如果截取值只有一位,那么就从当前值开始到字段最后一位之间的字符
            document.write("<br/>")
            //字符串反转
            var str5 = "abcdefg";
            var temp = "";
            for (var i = str5.length - 1; i >= 0; i--) {
                temp += str5.substr(i, 1);
            }
            document.write(temp);
            document.write("<br/>")
            var str6 = "abcdefg"
            //indexOf 返回字符所在当前字段的值,如果字符没有出现在该字段里面,则返回-1
            document.write(str6.indexOf("b"))
            document.write("<br/>");
            //lastIndexOf 截取字符所在最后一个位置的值
            document.write(str6.lastIndexOf("f"))
            document.write("<br/>")
            var a = "asdfghjjhgfdsa"
            //replace 替换字符。如果出现重复字符,只会替换字段中的第一个字符(坑)
            document.write(a.replace("s", "z"));
            document.write("<br/>")
            //trim 删除第一个字符之前和最后一个字符之后的空格
            // document.write(a.trim())
            //startsWith  检测字符是否以指定字符开头
            //语法结构 document.write(a.startsWith());
            //endsWith 检测字符是否以指定字符结尾
            //document.write(a.endsWith());
        </script>
    </body></html>
  • 相关阅读:
    InvokeRequired和Invoke
    DataGrid 得到DataGridRow 和DataGridColumn
    DataGrid 如何得到DataGridRow 和DataGridCell 对象
    安装Extended WPF Toolkit
    WPF DataGrid绑定一个组合列
    允许Root登录Docker ubuntu(MAC主机,使用portainer管理)
    photoshop人物美白教程:暗沉肤色提亮美白
    django中聚合aggregate和annotate GROUP BY的使用方法
    Django Model 基础数据库操作应用
    如何在mac上安装gitlab
  • 原文地址:https://www.cnblogs.com/001yjk/p/10617436.html
Copyright © 2020-2023  润新知