js string相关方法
1>concat() //合并返回新的字符串
var a="么么么么",b="ssss";
a.concat(b)
//"么么么么ssss"
2》indexOf() //返回匹配的第一个索引,没有的话返回-1
var a="么么么么",b="ssss"
a.indexOf(b)
//-1
var c="什么";
c.indexOf('么')
//1
3》lastIndexOf() //返回匹配的最后一个索引,没有返回-1
var c="什么是东什么是西";
c.lastIndexOf('么')
//
4>search() //查找字符串里子字符串的索引,没有的话返回-1
var c="什么是东什么是西";
c.search('么')
//
5>match() //在字符串里检索指定的值,返回字符串,没有的话返回null
var str="1 plus 2 equal 3"
str.match(/\d+/g)
// ["1", "2", "3"]
6》replace(oldval,newval) //新字符串替换匹配字符串
var c="什么是东什么是西";
c.replace("什么",'what')
//"what是东什么是西"
7》 split() //用于把一个字符串分割成字符串数组
"|a|b|c".split("|")
//将返回["", "a", "b", "c"] var d="什么是东什么是西";
d.split()
//["什么是东什么是西"]
8>length //返回字符创长度
var d="什么是东什么是西";
d.length
//
9>toLowerCase() //字母转小写 toUpperCase() // 字母转大写
var str="ssss"
str.toUpperCase()
//"SSSS"
var mm="AAAA";
mm.toLowerCase()
//"aaaa"
var nn="11"
nn.toUpperCase()
//"11"
10>charAt(index) //方法返回指定位置的字符
var d="什么是东什么是西";
d.charAt(3)
//"东"
11>substring(a,b) // 返回开始位置到结束位置的字符
substr(a,length) // 返回指定位置开始长度为length的字符串
slice(a,b)//返回开始到b位置的字符串
区别:substr参数为负数时,a为负数时加字符串的长度为真正值,length为0或负数时返回空的字符串
substring参数 a或者b为负数时直接替换成数字0,那个数字小那个数字为开始位置。
slice()参数为负的话,加上字符串长度,返回开始到结束位置的字符
js string相关方法的更多相关文章
- Right in the Center (js string algorithm)
Right in the Center (js string algorithm) codewars https://www.codewars.com/kata/5f5da7a415fbdc0001a ...
- 说说 js String
首先说说js的字符串,说到字符串这个就和我们原来的C# 代码有区别的就是,js里面没有chart类型.就是说他里面的 “ ”和‘ ’是要表达一样的意思. 其实这个里面就有一个问题了特别实在拼接字符串的 ...
- js string to int
一.js中string转int有两种方式 Number() 和 parseInt() <script> var str='1250' ; alert( Number(str) ...
- js string和number
number Js只有一种数字类型(包括整型,浮点型) 极大或极小的可用科学计数法来表示.(7.7123e+1) 所有js数字均为64位 Js所有的数字都存储为浮点型 小数的最大位数是17位 0开头的 ...
- js日期相关方法
/** * ===================================== * 日期相关方法 * ===================================== */ ;(fu ...
- js String对象
字符串(String) 字符串(String)使用长度属性length来计算字符串的长度: 在字符串中查找字符串 字符串使用 indexOf() 来定位字符串中某一个指定的字符首次出现的位置: 实例 ...
- js String对象中常用方法小结(字符串操作)
1.charCodeAt方法返回一个整数,代表指定位置字符的Unicode编码. strObj.charCodeAt(index) 说明: index将被处理字符的从零开始计数的编号.有效值为0到字符 ...
- javascript js string.Format()收集
方案1http://www.cnblogs.com/loogn/archive/2011/06/20/2085165.html String.prototype.format = function(a ...
- js String方法集合
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String//返回对应索引的字符 ...
随机推荐
- 第八周作业—N42-虚怀若谷
一.显示统计占用系统内存最多的进程,并排序 [root@centos7 ~]# ps -eo uid,pid,ppid,tty,c,time,cmd,%mem --sort=-%mem UID PID ...
- JavaScript正则表达式简介(一)
一.正则表达式 正则表达式Regular Expression,可以简写为regexp.regex或是RE. 正则表达式使用单个字符串来描述或是匹配一系列符合某个句法规则的字符串模型. 按照某种规则去 ...
- react native 之 在现有的iOS工程中集成react native
在现有的iOS工程中集成react native, 或者说将react native引入到iOS 项目,是RN和iOS混合开发的必经之路 参考官网教程:https://reactnative.cn/d ...
- Codeforce |Educational Codeforces Round 77 (Rated for Div. 2) B. Obtain Two Zeroes
B. Obtain Two Zeroes time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Apache2.4+PHP7.2环境搭建
Editplus生成码:http://www.jb51.net/tools/editplus/ 阿帕奇下载地址:https://www.apachehaus.com/cgi-bin/download. ...
- RFC、EMCA-262、TC-39等名词
请求意见稿(英语:Request For Comments,缩写:RFC)是一系列备忘录. The RFC series contains technical and organizational d ...
- 只有一个form 的程序, onactivate 只触发一次。
https://blog.csdn.net/saint13/article/details/454615 Form的onActivate事件 2005年08月15日 01:08:00 阅读数:3406 ...
- base64编解码的两个函数(安全版本)
void base64_encode_s(const unsigned char *str, long inlen, std::string& outstr, long* lpBufLen) ...
- 16/7/8_PHP-设置cookie会话控制(session与cookie)
设置cookie PHP设置Cookie最常用的方法就是使用setcookie函数,setcookie具有7个可选参数,我们常用到的为前5个: name( Cookie名)可以通过$_COOKIE[' ...
- Python笔记(二十六)_魔法方法_属性的魔法方法
属性的魔法方法 __getattribute__(self,name):当该类的属性被访问时,自动触发,是最先被触发的属性方法 __setattr__(self,name,value):当一个属性被设 ...