当前位置:网站首页>Content of string
Content of string
2022-07-07 08:01:00 【Code machine - Ying】
One , Loop operation of string
Loop traversal method of string :
for loop
for....in loop
for....of loop
Two , String query
1 character string .indexOf() Regular expressions are not supported
character string .search() regular expression
Query whether there are matching characters in the string
If there is an index subscript that returns the first occurrence
If there is no return -1
2 character string .lastIndexOf();
Query whether there are matching characters in the string
If there is an index subscript that returns the last occurrence
If there is no return -1
var str = ' How big is the big mouth monkey '; // Inquire about console.log( str.indexOf( ' Big ' ) ); console.log( str.search( ' Big ' ) ); console.log( str.lastIndexOf( ' Big ' ) );
3、 ... and String truncation
1 character string .substr( Parameters 1, Parameters 2)
Parameters 1 The starting position of the intercepted string
0 Or a positive number Index subscript of starting position
negative Intercept from the penultimate character to the last bit of the string
Parameters 2 Number of intercepted strings
If no parameters are set 2 Intercept to the end of the string
Set the number of intercepted characters
2 character string .substring( Parameters 1, Parameters 2)
Parameters 1 Intercepted string The starting position
0 Or a positive number Index subscript of starting position
negative Intercept from the first character
Parameters 2 The end position of the intercepted string
0 Or a positive number The interception result does not contain the end position
negative Intercept to the beginning of the string
// from The index subscript is 3 Start with the fourth character of Intercept to The last bit of the string var res1 = str.substr( 3 ); console.log( res1 ); // from The penultimate character begins Intercept to The last bit of the string var res2 = str.substr( -3 ); console.log( res2 ); // from The index subscript is 3 Start with the fourth character of Intercept 4 Characters var res3 = str.substr( 3 , 4 ); console.log( res3 ); // from The penultimate character begins Intercept Intercept 2 Characters var res4 = str.substr( -3 , 2 ); console.log( res4 ); // substring Intercepting string // The subscript from the index is 3 Start with the fourth character of Intercept to Last bit of string var res5 = str.substring( 3 ); console.log( res5 ); // Parameters 1 Cannot be set to a negative number Intercept from the beginning of the string // var res6 = str.substring( -3 ); // console.log( res6 ); // from Index subscript yes 3 Start intercepting the position of // Intercept to The index subscript is 10 The location of // however result barring The index subscript is 10 The location of var res7 = str.substring( 3 , 10 ); console.log( res7 ); var res8 = str.substring( 3 , -5 ); console.log( res8 );
Four String case is unified
character string .toLowerCase()
All characters are lowercase
character string .toUpperCase()
Capitalize all characters
var str = 'abCdEfGh' ; console.log(str.toLowerCase()) // All characters are lowercase console.log(str.toUpperCase()) // Capitalize all characters
5、 ... and Get character function
character string .charAt()
Get characters according to index subscript
character string .charCodeAt()
Get the characters according to the index subscript ASCII Code number
var str = 'abcedfg' ; console.log( str.charAt( 1 ) ); console.log( str.charCodeAt( 1 ) ); console.log( str[1] );
边栏推荐
- Installing postgresql11 database under centos7
- Pytest+allure+jenkins installation problem: pytest: error: unrecognized arguments: --alluredir
- [P2P] local packet capturing
- Pytest + allure + Jenkins Environment - - achèvement du remplissage de la fosse
- What are the positions of communication equipment manufacturers?
- C language queue
- 解决问题:Unable to connect to Redis
- [SUCTF 2019]Game
- 2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
- Quickly use Jacobo code coverage statistics
猜你喜欢

Qt学习27 应用程序中的主窗口

Explore Cassandra's decentralized distributed architecture

The charm of SQL optimization! From 30248s to 0.001s
![[UTCTF2020]file header](/img/e3/818e2d531a06ab90de189055f634ad.png)
[UTCTF2020]file header
![[GUET-CTF2019]虚假的压缩包](/img/a2/7da2a789eb49fa0df256ab565d5f0e.png)
[GUET-CTF2019]虚假的压缩包

Padavan manually installs PHP

Introduction to basic components of wechat applet

【数字IC验证快速入门】15、SystemVerilog学习之基本语法2(操作符、类型转换、循环、Task/Function...内含实践练习)

Thinkcmf6.0 installation tutorial
![[experience sharing] how to expand the cloud service icon for Visio](/img/42/dba9f78f3fb2049dad8b343b0b36e5.png)
[experience sharing] how to expand the cloud service icon for Visio
随机推荐
C语言二叉树与建堆
Visualization Document Feb 12 16:42
[webrtc] M98 screen and window acquisition
[guess-ctf2019] fake compressed packets
Problem solving: unable to connect to redis
Main window in QT learning 27 application
[Stanford Jiwang cs144 project] lab3: tcpsender
padavan手动安装php
Mysql高低版本切换需要修改的配置5-8(此处以aicode为例)
[webrtc] m98 Screen and Window Collection
Why should we understand the trend of spot gold?
What are the positions of communication equipment manufacturers?
Linux server development, detailed explanation of redis related commands and their principles
[2022 ciscn] replay of preliminary web topics
Iterable、Collection、List 的常见方法签名以及含义
2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
图解GPT3的工作原理
快速使用 Jacoco 代码覆盖率统计
Pytorch parameter initialization
Linux server development, SQL statements, indexes, views, stored procedures, triggers


