当前位置:网站首页>字符串常用方法(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()
使用指定的分隔符将一个字符串拆分为多个子字符串数组并返回边栏推荐
- Introduction and use of Pinia
- Win10 super good-looking mouse theme, you also try it
- 0613 ~ self study
- 《STL源码剖析》应该怎样读?
- OpenCV 图片旋转
- Growth of operation and maintenance Xiaobai - week 8 of Architecture
- 05mysql lock analysis
- C language programming training topics: K characters in left-handed string, little Lele and Euclidean, printing arrow pattern, civil servant interview, poplar matrix
- Use of jumpserver
- 0615~用自定义注解实现RBAC权限管理
猜你喜欢

Mozilla foundation released 2022 Internet health report: AI will contribute 15.7 trillion yuan to the global economy in 2030, and the investment in AI in the United States last year was nearly three t

PXE efficient batch network installation

Stream, file, IO
去不图床容量兑换

Handwritten blog platform ~ the next day
![[OBS] dependency Library: x264 vs Build](/img/24/4caea5dc6ff092a3161f43b6026d25.png)
[OBS] dependency Library: x264 vs Build

手写博客平台~第二天

Inherit, override, overload

邻接表的定义和存储以及有向图无向图的邻接存储

Go language interface and type
随机推荐
0613 ~ self study
C language custom type explanation - Consortium
pinia 入门及使用
Still building projects from scratch? This upgraded rapid development scaffold is worth a try!
Codeforces Round #794 (Div. 2)(A.B.C)
运维小白成长记——架构第8周
6126. 设计食物评分系统
Shengxin commonly used analysis graphics drawing 02 -- unlock the essence of volcano map!
Section 11 cache avalanche, hot data failure follow Daewoo redis ------- directory post
如何向 google colab 快速上传文件
Shanghai Jiaotong University team used joint deep learning to optimize metabonomics research
SV casts and constants
0621~ES&Lucene
Model saving and loading of sklearn
0627~ holiday knowledge summary
redis集群的三种方式
面会菜评论分析
单细胞代码解析-妇科癌症单细胞转录组及染色质可及性分析1
Awk from getting started to getting into the ground (19) awk extensions make awk even stronger
Flink operation Hudi data table