zoukankan      html  css  js  c++  java
  • JS字符串

    原始类型的值如:'hell'    只要对其调用字符串API,会自动创建该类型的包装类型对象

    字符串:JS的一种数据类型,字符串不可变,字符串API不能修改,返回一个新的变量

    字符的Unicode表示法:u0000-uFFFF之间的字符超出表现为双字节

    str.length//表示字符的个数,超出范围即使是一个也体现为2
    API:

      1.toUpperCase()                   //转大写

      2.toLowerCase()                   //转小写

      3.charAt()                              //获取指定位置的字符 str.charAt(i)

      4.charCodeAt()                     //获取指定位置的unicode号   str.charCodeAt(i)

      5.fromCharCode()                //unicode反转回字     str.fromCharCode(unicode)

      6.substring()                         //截取指定区间字符串  str.substring(start,n)   start必填  不接受负参数

      7.substr()                              //同上 str.substr(start,n)   start必填 接受负参数,表示从尾开始 -1表示从末尾

      8.slice()                                //可以没参数,表示复制该字符串,也可以为负参数

     查找关键字

      1.str.indexOf('关键词',fromi)         //每次只能找一个 返回位置,如果没有返回-1

      2.str.search(正则)                        //只找第一个关键字  返回位置,如果没有返回-1

      3.str.match(正则)                         //查找的返回放在数组中,没找到返回null  匹配所有加g  返回内容

      4.reg.exec(str)                             //查找返回放在数组中,0:内容   index:位置    

     替换

      1.简单替换

        str.replace(reg,新值)

      2.高级替换

        str.replace(reg,function(kw){

          kw:查到关键词内容

          return 替换的值

        })

     切割

      str.split('切割符')   

      str.split()//'hello'.split()        ['hello']

      str.split('') //'he'.split('')        ['h','e']

  • 相关阅读:
    06 Python类、对象
    05 Python DNS域名轮询业务监控
    04 Python字符串
    03 Python函数
    02 Python循环
    执行config文件时,config.log中报错xcrun: error: active developer path ("/Applications/Xcode.app/Contents/Developer") does not exist, use xcode-select to change
    浏览我的php网页时,出现的都是网页的代码
    php
    [转载]用c写PHP的扩展接口(php5,c++)
    PHP扩展编写示例
  • 原文地址:https://www.cnblogs.com/shui1993/p/9948079.html
Copyright © 2011-2022 走看看