zoukankan      html  css  js  c++  java
  • JS String对象方法

    charAt  返回指定索引位置处的字符  str.charAt(index);
    
    charCodeAt 返回一个整数,代表指定位置上字符的 Unicode 编码。 str.charCodeAt(index)
    
    concat 返回字符串值,该值包含了两个或更多个提供的字符串的连接。 str.concat(str1,str2);
    
    fromCharCode  从一些 Unicode 字符值中返回一个字符串。String.fromCharCode(100,101,102);//def
    
    indexOf  返回 String 对象内第一次出现子字符串的字符位置。  str.indexOf('test');
    
    lastIndexOf  返回 String 对象中子字符串最后出现的位置。  str.lastIndexOf('test');
    
    match   使用正则表达式模式对字符串执行查找,并将包含查找的结果作为数组返回。
             str.match(rgExp);
                 var r, re;         // 声明变量。
               var s = "The rain in Spain falls mainly in the plain";
                re = /ain/i;    // 创建正则表达式模式。
               r = s.match(re); 
    
    replace  返回根据正则表达式进行文字替换后的字符串的复制。 str.replace('t','a');
            如果不使用正则表达式,则只能替换一个,使用正则表达式才能全部替换
              var r, re;                    // 声明变量。
                var ss = "The man hit the ball with the bat.
    ";
                 ss += "while the fielder caught the ball with the glove.";
                 re = /The/g;             // 创建正则表达式模式。
                 r = ss.replace(re, "A");    // 用 "A" 替换 "The"。
    
    
    
    search  返回与正则表达式查找内容匹配的第一个子字符串的位置。 str.search('t');
         var r, re;                   // 声明变量。
            var s = "The rain in Spain falls mainly in the plain.";
            re = /falls/i;            // 创建正则表达式模式。
            r = s.search(re);            // 查找字符串。
    
    slice 返回字符串的片段。 str.slice(start,end);
    
    split 将一个字符串分割为子字符串,然后将结果作为字符串数组返回。 str.split('==');
              var s, ss;
                var s = "The rain in Spain falls mainly in the plain.";
               // 在每个空格字符处进行分解。
                ss = s.split(" ");
    
    substr  返回一个从指定位置开始的指定长度的子字符串。str.substr(start [, length ])
            str.substr(512);从5开始长度12
    
    substring  返回位于 String 对象中指定位置的子字符串。 str.substring(start, end);
    
    toLowerCase  返回一个字符串,该字符串中的字母被转换为小写字母。  str.toLowerCase( )
    
    toUpperCase  返回一个字符串,该字符串中的所有字母都被转化为大写字母。 str.toUpperCase( )
    
    toString   返回对象的字符串表示。 obj.toString([radix])
            radix 可选项。指定将数字值转换为字符串时的进制。
    
    
    
            
  • 相关阅读:
    How to Setup a Private Proxy Server on EC2 in Under 10 Minutes
    How to Create a Cron Job (Scheduled Task) for Your Website or Blog
    NPM, BOWER, GIT, AND BASH PROXY CONFIGURATIONS
    Android: 通过Runtime.getRuntime().exec调用底层Linux下的程序或脚本
    Proguard breaking audio file in assets or raw
    SOCKSify Ruby
    UNIX / Linux: 2 Ways to Add Swap Space Using dd, mkswap and swapon
    窗体之间传值的方法
    扩展方法,
    反射 type 的基本用法,动态加载插件
  • 原文地址:https://www.cnblogs.com/bruce-gou/p/5727584.html
Copyright © 2011-2022 走看看