第132天 原生的字符串操作方法有哪些?请列举并描述其功能
Activity
qhdxwdm commentedon Aug 25, 2019
length 返回字符串长度
split 返回数组
...
whitesky1225 commentedon Aug 26, 2019
先补充几个:
string.split('')字符串转化成数组;
string.includes(val)包含某个字符串,返回布尔值;
string.startsWith(val)以...开始
string.endsWith(val)以...结束
nowherebutup commentedon Aug 26, 2019
补充几个;
EragonBubble commentedon Aug 26, 2019
补充 replace, match
LinStan commentedon Aug 26, 2019
String.concat() 连接两个字符串
String.substr(startIndex,length) 截取部分字符串,第一个参数是开始index,第二个是截取长度。
String.substring(startIndex,endIndex) 截取部分字符串,第一个是开始索引,第二个是结束索引。
String.toUpperCase() String.toLowerCase() 转为大小写
String.indexOf(searchString) 找对应的索引
forever-z-133 commentedon Aug 26, 2019
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/prototype
一般这种就是看官方最简单了。
charAt
、charCodeAt
、codePointAt
、concat
、includes
、endsWith
、indexOf
、lastIndexOf
、localeCompare
、match
、normalize
、padEnd
、padStart
、repeat
、replace
、search
、slice
、split
、startsWith
、substr
、substring
、toLocaleLowerCase
、toLocaleUpperCase
、toLowerCase
、toUpperCase
、trim
cai1994214 commentedon Sep 6, 2021
so cool
d4c-27 commentedon Apr 6, 2022
str.startsWith() 参数字符串是否在原字符串头部 返回布尔值
str.endsWith() 参数字符串是否在原字符串尾部 返回布尔值
str.repeat(n) 将原字符串重复n次,返回新字符串
str.trimStart()清空头空格
str.trimEnd()清空尾空格
str.substring(start,end)返回截取的字符串,不包含end
str.substr(start,length)返回起始位置后多少元素长度
str.slice(start,end)返回(start,end]区间字符串
xiaoqiangz commentedon Jul 12, 2022
str.split() 字符转数组
str.trim() 去除空格
str.replace() 内容替换
str.substr() 字符串截取
str.slice() 返回区间内字符串
str.repeat() 重复字符串
str.substring()
str.includes() 判断字符串中是否包含该字符
str.indexOf()
panpanxuebing commentedon Dec 17, 2024
打开控制台,输入 String.prototype