Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[js] 第132天 原生的字符串操作方法有哪些?请列举并描述其功能 #1114

Open
haizhilin2013 opened this issue Aug 25, 2019 · 9 comments
Labels
js JavaScript

Comments

@haizhilin2013
Copy link
Collaborator

第132天 原生的字符串操作方法有哪些?请列举并描述其功能

@haizhilin2013 haizhilin2013 added the js JavaScript label Aug 25, 2019
@qhdxwdm
Copy link

qhdxwdm commented Aug 25, 2019

length 返回字符串长度
split 返回数组
...

@whitesky1225
Copy link

先补充几个:
string.split('')字符串转化成数组;
string.includes(val)包含某个字符串,返回布尔值;
string.startsWith(val)以...开始
string.endsWith(val)以...结束

@nowherebutup
Copy link

先补充几个:
string.split('')字符串转化成数组;
string.includes(val)包含某个字符串,返回布尔值;
string.startsWith(val)以...开始
string.endsWith(val)以...结束

补充几个;

  • string.repeat(num); // 返回新字符串,num 表示将原字符串重复几遍 不可接受负数及 infinity
  • string.padStart(len,str),string.padEnd(len,str); // 分别为头尾补全字符串的长度(第一个参数为最小长度,第二个参数为用来补全的字符串)

@EragonBubble
Copy link

补充 replace, match

@LinStan
Copy link

LinStan commented Aug 26, 2019

String.concat() 连接两个字符串
String.substr(startIndex,length) 截取部分字符串,第一个参数是开始index,第二个是截取长度。
String.substring(startIndex,endIndex) 截取部分字符串,第一个是开始索引,第二个是结束索引。
String.toUpperCase() String.toLowerCase() 转为大小写
String.indexOf(searchString) 找对应的索引

@forever-z-133
Copy link

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/prototype
一般这种就是看官方最简单了。

charAtcharCodeAtcodePointAtconcatincludesendsWithindexOflastIndexOflocaleComparematchnormalizepadEndpadStartrepeatreplacesearchslicesplitstartsWithsubstrsubstringtoLocaleLowerCasetoLocaleUpperCasetoLowerCasetoUpperCasetrim

@cai1994214
Copy link

so cool

@d4c-27
Copy link

d4c-27 commented 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
Copy link

str.split() 字符转数组
str.trim() 去除空格
str.replace() 内容替换
str.substr() 字符串截取
str.slice() 返回区间内字符串
str.repeat() 重复字符串
str.substring()
str.includes() 判断字符串中是否包含该字符
str.indexOf()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js JavaScript
Projects
None yet
Development

No branches or pull requests

10 participants