zoukankan      html  css  js  c++  java
  • 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()不全字符串。

  • 相关阅读:
    va_list/va_start/va_arg/va_end深入分析【转】
    Linux Kernel中断子系统来龙去脉浅析【转】
    Linux系统调用---同步IO: sync、fsync与fdatasync【转】
    Linux中变量#,#,@,0,0,1,2,2,*,$$,$?的含义【转】
    linux下的module_param()解释【转】
    Makefile 使用总结【转】
    FLASH的知识【转】
    Linux MTD系统剖析【转】
    linux的mtd架构分析【转】
    linux设备树笔记__dts基本概念及语法【转】
  • 原文地址:https://www.cnblogs.com/hexiaobao/p/10181362.html
Copyright © 2011-2022 走看看