zoukankan      html  css  js  c++  java
  • 【javascript】字符串对象常用 api

    concat(str1,str2,···)

    连接字符串

    indexOf(str,start)

    返回 str 在字符串中首次出现的位置

    var str = "hello world";  
    str.indexOf("hello");  // 0  
    str.indexOf("o",5);  // 7  
    str.indexOf("World");  // -1

    lastIndexOf(str,start)

    返回 str 在字符串中最后出现的位置

    var str = "hello world";  
    str.lastIndexOf("hello");  // 0  
    str.lastIndexOf("o",3);  // -1  
    str.lastIndexOf("o",5);  // 4  

    replace(regexp/substr,replacement)

    在字符串中用一些字符替换另一些字符,或替换一个与正则匹配的字串

    var str = "I is Allen.";  
    str.replace("is","am");  // "I am Allen."

    slice(start,end)

    返回字符串的片段

    var str = "I am Jack.";  
    str.slice(3,7);  // "m Ja"  
    str.slice(3);  // "m Jack."  
    str.slice(3,-3);  // "m Ja"

    split(separator,limit)

    将一个字符串分割为子串,然后将结果作为字符串数组返回

    var str = "hello world";  
    str.split(" ");  // ["hello","world"]  
    str.split(" ",1);  // ["hello"]

    substr(start,lenght)

    返回一个从指定位置开始的指定长度的字串

    var str = "how do you do?";  
    str.substr(4,2);  // "do"  
    str.substr(4);  // "do you do?"  
    str.substr(4,0);  // " "  
    str.substr(4,-1);  // " "  
    str.substr(-3);  // "do?"

    substring(start,end)

    返回位于 string 对象中指定位置的字串,包含 start 处字符,但不包含 end 处字符

    var str = "how do you do?";
    str.substring(0,3);  // "how" 

    toLowerCase()

    把字符串转换为小写

    toUpperCase()

    把字符串转换为大写

    var str = "How do you do?";  
    str.toLowerCase();  // "how do you do?"  
    str.toUpperCase();  // "HOW DO YOU DO?" 
  • 相关阅读:
    spring中Bean的生命周期
    java之多线程
    struts2配置详解
    值栈
    数据校验和国际化
    2016年9月23日试题整理
    SpringMVC 文件上传下载
    CSS3 新增属性
    SpringMVC数据校验
    java中进程与线程--三种实现方式
  • 原文地址:https://www.cnblogs.com/yjzhu/p/2758771.html
Copyright © 2011-2022 走看看