当前位置:网站首页>字符串常用方法(2)
字符串常用方法(2)
2022-07-24 18:08:00 【无围之解】
二、字符串常用方法
1.charAt()
返回指定索引位置处的字符。类似于数组用中括号获取相应下标位置的数据。
var str = 'abcdefg'
console.log(str.charAt(2)) // 输出 'c'
console.log(str[2]) // 输出 'c'
2.concat()
类似数组的concat(),用来返回一个合并拼接两个或两个以上字符串。原字符串不变。
const str1 = 'abcdefg'
const str2 = '1234567'
const str3 = str1.concat(str2)
console.log(str3) // 输出 'abcdefg1234567'
3.indexOf()、lastIndexOf()
indexOf,返回一个字符在字符串中首次出现的位置,lastIndexOf返回一个字符在字符串中最后一次出现的位置。
const str = 'abcdcefcg'
console.log(str.indexOf('c')) // 输出 '2'
console.log(str.lastIndexOf('c')) // 输出 '7'
4.slice()
提取字符串的片断,并把提取的字符串作为新的字符串返回出来。原字符串不变。
const str = 'abcdefg'
console.log(str.slice()) // 输出 'abcdefg', 不传递参数默认复制整个字符串
console.log(str.slice(1)) // 输出 'bcdefg',传递一个,则为提取的起点,然后到字符串结尾
console.log(str.slice(2, str.length-1)) // 输出'cdef',传递两个,为提取的起始点和结束点
5.split()
使用指定的分隔符将一个字符串拆分为多个子字符串数组并返回边栏推荐
- 2022最新短视频去水印解析API接口分享
- 快速完成intelij idea的单元测试JUnit4设置
- C语言自定义类型 — 枚举
- Opencv picture rotation
- Go to bed capacity exchange
- 0615~用自定义注解实现RBAC权限管理
- How does win11 enhance the microphone? Win11 enhanced microphone settings
- How to prepare for hyperinflation
- How to quickly upload files to Google Lab
- 0615 ~ realize RBAC permission management with user-defined annotations
猜你喜欢

Win10 super good-looking mouse theme, you also try it

Brats18 - Multimodal MR image brain tumor segmentation challenge continued

Gan Development Series II (pggan, Singan)

In depth analysis of the famous Alibaba cloud log4j vulnerability

【网络安全】网站中间件存在的解析漏洞

T245982 "kdoi-01" drunken flower Yin

C language custom type explanation - Consortium

Get the data of Tongcheng (elong) Hotel

ShardingSphere数据库读写分离

0625~<config>-<bus>
随机推荐
Three ways of redis cluster
OpenCV 图片旋转
Definition and storage of adjacency table and adjacency storage of directed graph and undirected graph
Alibaba /166 obtains the API instructions for all products in the store
700. 二叉搜索树中的搜索-dfs法
安装JumpServer
0629 ~ SaaS platform design ~ global exception handling
2022最新短视频去水印解析API接口分享
0616项目二结束~~总总结
Still reading logs on the command line? Use kibana, visual log analysis yyds!
获取1688app上原数据 API
Brats18 - Multimodal MR image brain tumor segmentation challenge continued
(mandatory) override equals must override hashcode (principle analysis)
Blackmagic Fusion Studio 18
如何向 google colab 快速上传文件
Mac database management software Navicat premium essentials mac
213. Looting II - Dynamic Planning
T245982 "kdoi-01" drunken flower Yin
Int8 & int8, have you ever stumbled like this?
Blackmagic Fusion Studio 18