• String的使用


                                    String的常用方法

    方法

    说明

    Anchor()

    创建html

    Concat()

    把字符串连接起来

    indexOf()

    查找字符出现的位置

    lastIndexOf()

    查找最后出现字符

    charAt()

    返回指定位置的字符

    Substring()

    截取字符串

    Substr()

    截取字符串

    Spilt()

    分割字符串

    toLowerCase()

    把字符串转换成小写字母

    toUpperCase()

    把字符串转换成大写字母

    Sub()

    把字符串显示为下标

    Sup()

    把字符串显示为上标

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" language="javascript">
     /************创建字符串对象***********/
     //创建字符串对象(方法一)
     //var str = "hello world";
     //创建字符串对象(方法一)
     //var str = new String("hello world");
     
     /***********字符串对象的常用方法***************/
     var str = "hello world";
     //indexOf用来查找指定子字符串的第一出现的索引位置,找不到就返回-1
     //document.write(str.indexOf("o",0));//输出4
     //document.write(str.indexOf("o",5));//输出7
     //lastIndexOf用来查找指定子字符串出现的最后位置,找不到就返回-1(注意:本方法是从字符串的最后向前面进行查找,第二个参数代表开始查找的索引位置)
     //document.write(str.lastIndexOf('o',str.length));
     /*********substring与substr*********************/

    var str = "hello world";
     //参数一:开始截取的下标  参数二:截取到第几个字符
     document.write(str.substring(1,3));//输出el
     document.write("<br>");
     //参数一:开始截取的下标  参数二:截取多少个字符
     document.write(str.substr(1,3));
     document.write("<br>");
     document.write(str.length);//输出字符串的长度

    </script>

    </head>

    <body>

    </body>

    </html>

  • 相关阅读:
    [PATCH] input: add driver for Bosch Sensortec's BMA150 accelerometer
    linux内核GPIO模拟I2C实例
    修改默认apn数据的方法
    Android平台开发WIFI function portingWIFI功能移植
    Silverlight中后台获取样式的方法
    Silverlight中读取Word
    Silverlight找到模板中的子控件
    根据年月来获取该年该月的天数
    Silverlight中Treeview中判断当前节点是否含有父节点
    修改 Linux /etc/profile 以后如何生效
  • 原文地址:https://www.cnblogs.com/danmao/p/3815778.html
Copyright © 2020-2023  润新知