• ES6标准入门之字符串的拓展讲解


      在开始讲解ES6中字符串拓展之前,我们先来看一下ES5中字符串的一些方法。

        获取字符串长度 str.length
        分割字符串 str.split()
        拼接字符串 str1+str2 或 str1.concat(str2)
        替换字符串 str.replace(“玩游戏”,”好好学习”)
        提取子字符串 str.slice(start, end)或str.substring(start,end)或myStr.substr(start,length)
        切换字符串大小写 str.toLowerCase()和str.toUpperCase()
        比较字符串 str1.localeCompare(str2)
        匹配字符串 str.match(pattern)或pattern.exec(str)或str.search(pattern)
        根据位置查字符 str.charAt(index)
        根据位置字符Unicode编码 str.charCodeAt(index)
        根据字符查位置 str.indexOf(“you”)从左,myStr.lastIndexOf(“you”)从尾 或str.search(‘you’)
        原始数据类型转字符串 String(数据) 或利用加号
        字符串转原始数据类型 数字Number(”) // 0 布尔Boolean(”) // 0
        自己构建属性和方法 String.prototype.属性或方法= function(参数){代码}

      想知道这些方法如何使用的同学请自行百度。

      JavaScript允许采用uxxxx形式标识一个字符,其中xxxx表示字符的Unicode码点,比如:"u0061"就代表字符a,但是,这种表示法只限于u0000~uFFFF之间的字符。超出这个范围的字符,必须用两个双字节的形式表达。

      ES6新增字符串遍历接口,for . . . of

      ES6新增includes()、startsWith()、endsWith()方法,用于检测字符串是否含有子串。

      ES6现新增padStart()、padEnd()不全字符串。

  • 相关阅读:
    700.二叉搜索树中的搜索
    645.错误的集合
    567.字符串的排列
    560.和为K的子数组
    518.零钱兑换 II
    516.最长回文子序列
    509.斐波那契数
    503.下一个更大元素 II
    496.下一个更大元素 I
    leetcode 1171 Remove Zero Sum Consecutive Nodes from Linked List
  • 原文地址:https://www.cnblogs.com/hexiaobao/p/10181362.html
Copyright © 2020-2023  润新知