当前位置:网站首页>The use method of string is startwith () - start with XX, endswith () - end with XX, trim () - delete spaces at both ends
The use method of string is startwith () - start with XX, endswith () - end with XX, trim () - delete spaces at both ends
2022-07-06 21:10:00 【viceen】
How to use strings startwith()- With XX start 、endsWith()- With XX ending 、trim()- Delete spaces at both ends
1、startsWith() Method
- Used to determine whether the string starts with fixed data .
'abc'.startsWith('a') //true
'abc'.startsWith('d') //false
- The method also has a second parameter , You can judge from the specified position of the string , The default is 0
'abcdefg'.startsWith('bcd')) //false
'abcdefg'.startsWith('bcd',1)) //true
2、endsWith() Method
- The second parameter specifies the length for the selected string
'abc'.endsWith('c') //true
'abc'.endsWith('bc') //true
'abc'.endsWith('a') //false
'abcdefg'.endsWith('def')) //false
'abcdefg'.endsWith('def',6)) //true
3、trim() Method
- From the original string The beginning and the end Delete the blank space , The space in the middle is not processed .
- It does not affect the original string itself , Returns a new string .
'Testing'.trim() //'Testing'
' Testing'.trim() //'Testing'
' Testing '.trim() //'Testing'
'Testing '.trim() //'Testing'
example
<script>
var str = " yang ";
console.log(str);// Output yang
var str1 = str.trim();// There is a return value , To accept a value
console.log(str1);// Output yang ( There are no spaces )
var str2 = "ya ng";
console.log(str2);// Output "ya ng"
var str3 = str2.trim();
// From a string of ** Both ends ** Delete white space characters . The space in the middle of the string will not be deleted
console.log(str3);// Output "ya ng"
</script>
Use regular expressions to realize string trim Method
String.prototype._trim = function() {
return this.replace(/^(\s*)|(\s*)$/g, '')
}
var str = ' ssss '
console.log(str) // ditto
console.log(str.length) // 11
var strNew = str._trim()
console.log(strNew) // 'ssss'
console.log(strNew.length) // 4
- there * Represents a match 0 One or more ,
- At this point, we need to consider two situations , One is that there is a space in front , The other is that there is a space after . So we use
|To match . - And use
replaceTo replace it , Only the first one will be replaced , So we need to add global matchingg.
边栏推荐
- Nodejs tutorial let's create your first expressjs application with typescript
- Swagger UI tutorial API document artifact
- 基于STM32单片机设计的红外测温仪(带人脸检测)
- The most comprehensive new database in the whole network, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, flying Book Multidimensional table, heipayun, Zhix
- User defined current limiting annotation
- Chris LATTNER, the father of llvm: why should we rebuild AI infrastructure software
- Spark SQL chasing Wife Series (initial understanding)
- Aiko ai Frontier promotion (7.6)
- Le langage r visualise les relations entre plus de deux variables de classification (catégories), crée des plots Mosaiques en utilisant la fonction Mosaic dans le paquet VCD, et visualise les relation
- 什么是RDB和AOF
猜你喜欢

新型数据库、多维表格平台盘点 Notion、FlowUs、Airtable、SeaTable、维格表 Vika、飞书多维表格、黑帕云、织信 Informat、语雀

Opencv learning example code 3.2.3 image binarization

Infrared thermometer based on STM32 single chip microcomputer (with face detection)

1500万员工轻松管理,云原生数据库GaussDB让HR办公更高效

愛可可AI前沿推介(7.6)

No Yum source to install SPuG monitoring

OneNote 深度评测:使用资源、插件、模版

LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件

Distributed ID

C language operators
随机推荐
Select data Column subset in table R [duplicate] - select subset of columns in data table R [duplicate]
Dynamically switch data sources
c#使用oracle存储过程获取结果集实例
PG basics -- Logical Structure Management (transaction)
Introduction to the use of SAP Fiori application index tool and SAP Fiori tools
OAI 5G NR+USRP B210安装搭建
请问sql group by 语句问题
js中,字符串和数组互转(二)——数组转为字符串的方法
Comprehensive evaluation and recommendation of the most comprehensive knowledge base management tools in the whole network: flowus, baklib, jiandaoyun, ones wiki, pingcode, seed, mebox, Yifang cloud,
Web开发小妙招:巧用ThreadLocal规避层层传值
SAP Fiori应用索引大全工具和 SAP Fiori Tools 的使用介绍
【论文解读】用于白内障分级/分类的机器学习技术
R语言可视化两个以上的分类(类别)变量之间的关系、使用vcd包中的Mosaic函数创建马赛克图( Mosaic plots)、分别可视化两个、三个、四个分类变量的关系的马赛克图
New database, multidimensional table platform inventory note, flowus, airtable, seatable, Vig table Vika, Feishu multidimensional table, heipayun, Zhixin information, YuQue
C language games - minesweeping
Math symbols in lists
for循环中break与continue的区别——break-完全结束循环 & continue-终止本次循环
@Detailed differences among getmapping, @postmapping and @requestmapping, with actual combat code (all)
【深度学习】PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
基于STM32单片机设计的红外测温仪(带人脸检测)