zoukankan      html  css  js  c++  java
  • js 字符串操作

    字符串操作也是项目中处理返回数据常用到的。

    ES5:

    split():字符串转数组,默认不隔开=>返回数组

    substr(a,b):从a处开始,截取字符串度为b的字符串=>返回指定字符串

    indexOf(a):检索字符串位置,没有返回-1=>返回指定字符串位置

    replace(a,b):将a位置的字符替换成b=>返回替换后的字符串

    parseInt():字符串转数字=>返回数字

    match(reg):字符串过滤=>返回符合正则的字符串

    toLowerCase():字符串转小写=>返回字符串

    toUpperCase():字符串转大写=>返回字符串

    trim():去掉空格=>返回字符串

    charAt(index):返回指定位置的字符

    substring(a,b):从a处开始,截取到b位置=>返回指定字符串

    ES6:

    includes(searchString,position):表示是否找到了指定的参数字符串,返回true or false

    position:表示指定字符串开始位置

    var str='abcdefg';
    str.includes('a')   //true
    str.includes('A')   //false
    str.includes('a',0) //true
    str.includes('a',3)   //false

    startsWith(searchString,position)):表示是否以指定的字符串为开头,返回true or false

    position:表示指定字符串开始位置

    var str='abcdefg';
    str.startsWith('a');   //true
    str.startsWith('c');   //false
    str.startsWith('ab',0); //true
    str.startsWith('de',3);   //true

    endsWith(searchString,position)):表示是否以指定的字符串为开头,返回true or false

    position:表示指定字符串结束位置

    var str='abcdefg';
    str.endsWith('g');   //true
    str.endsWith('c');   //false
    str.endsWith('bc',3); //true
    str.endsWith('bc',2);   //false
  • 相关阅读:
    【C#高级】泛型(一)
    【C#】RGB转CMYK
    C#读写Excel
    H5+MUI上传文件
    完整登录流程包含第三方登录,很详细值得推荐
    [MVC]多文件、超大文件上传
    [SQL Server] 无法连接到本地数据库
    “System.OutOfMemoryException”类型的异常在 mscorlib.dll 中发生,但未在用户代码中进行处理
    MVC缓存(二)
    MVC缓存(一)
  • 原文地址:https://www.cnblogs.com/artimis/p/9003236.html
Copyright © 2011-2022 走看看