JS中string方法中常用方法之六:String.prototype.substring() 2022-09-26 01:57 79阅读 0赞 String.prototype.substring()返回字符串两个索引之间(或到字符串末尾)的子串。 语法:str.substring(indexStart\[, indexEnd\]) 详解: substring 提取从 indexStart 到 indexEnd(不包括)之间的字符。特别地: 如果 indexStart 等于 indexEnd,substring 返回一个空字符串。 如果省略 indexEnd,substring 提取字符一直到字符串末尾。 如果任一参数小于 0 或为 NaN,则被当作 0。 如果任一参数大于 stringName.length,则被当作 stringName.length。 如果 indexStart 大于 indexEnd,则 substring 的执行效果就像两个参数调换了一样。例如,str.substring(1, 0) == str.substring(0, 1)。 //举例如下 var anyString = "Mozilla"; // 输出 "Moz" console.log(anyString.substring(0,3)); console.log(anyString.substring(3,0)); console.log(anyString.substring(3,-3)); console.log(anyString.substring(3,NaN)); console.log(anyString.substring(-2,3)); console.log(anyString.substring(NaN,3)); // 输出 "" console.log(anyString.substring(4,4)); // 输出 "zill" console.log(anyString.substring(2)); // 输出 "Mozilla" console.log(anyString.substring(0,7)); console.log(anyString.substring(-2,7)); console.log(anyString.substring(NaN,7)); console.log(anyString.substring(0,10));
相关 JS中string方法中常用方法之二:String.prototype.concat() String.prototype.concat()将一个或多个字符串与原字符串连接合并,形成一个新的字符串并返回。concat 方法并不影响原字符串。 语法:str.con 深藏阁楼爱情的钟/ 2022年09月26日 01:53/ 0 赞/ 64 阅读
相关 JS中string方法中常用方法之三:String.prototype.charCodeAt() String.prototype.charCodeAt(index)返回一个整数,代表指定位置字符的Unicode编码。 index将被处理字符的从零开始计数的编号。有效值为 落日映苍穹つ/ 2022年09月26日 01:57/ 0 赞/ 84 阅读
相关 JS中string方法中常用方法之四:String.fromCharCode() String.fromCharCode()根据指定的 Unicode 编码中的序号值来返回一个字符串。 语法:String.fromCharCode(num1, ... 向右看齐/ 2022年09月26日 01:57/ 0 赞/ 286 阅读
相关 JS中string方法中常用方法之五:String.prototype.slice() String.prototype.slice()从左向右提取字符串中的一部分,并返回这个新的字符串。 语法:str.slice(beginSlice\[, endSlice 逃离我推掉我的手/ 2022年09月26日 01:57/ 0 赞/ 95 阅读
相关 JS中string方法中常用方法之六:String.prototype.substring() String.prototype.substring()返回字符串两个索引之间(或到字符串末尾)的子串。 语法:str.substring(indexStart\[, in 末蓝、/ 2022年09月26日 01:57/ 0 赞/ 80 阅读
相关 JS中string方法中常用方法之七:String.prototype.search() String.prototype.search()执行一个查找,看该字符串对象与一个正则表达式是否匹配。 语法:str.search(regexp) 参数regexp: ╰+哭是因爲堅強的太久メ/ 2022年09月26日 01:58/ 0 赞/ 103 阅读
相关 JS中string方法中常用方法之八:String.prototype.indexOf() String.prototype.indexOf()返回指定值在字符串对象中首次出现的位置。 从 fromIndex 位置开始查找,如果不存在,则返回 -1。 语法:s Myth丶恋晨/ 2022年09月26日 01:59/ 0 赞/ 149 阅读
相关 JS中string方法中常用方法之九:String.prototype.match() String.prototype.match()当字符串匹配到正则表达式(regular expression)时,match() 方法会提取匹配项。 语法:str.mat 桃扇骨/ 2022年09月26日 02:00/ 0 赞/ 93 阅读
相关 JS中string方法中常用方法之十一:String.prototype.toLocaleUpperCase() String.prototype.toLocaleUpperCase()使用本地化(locale-specific)的大小写映射规则将输入的字符串转化成大写形式并返回结果字符串 系统管理员/ 2022年09月26日 02:00/ 0 赞/ 86 阅读
相关 JS中string方法中常用方法之十三:String.prototype.replace() String.prototype.replace()使用一个替换值(replacement)替换掉一个匹配模式(pattern)在原字符串中某些或所有的匹配项,并返回替换后的新 淩亂°似流年/ 2022年09月26日 02:08/ 0 赞/ 79 阅读
还没有评论,来说两句吧...