当前位置:网站首页>ES6 new method of string
ES6 new method of string
2022-07-02 01:19:00 【I'm Lao Wang】
1、String.formCodePoint(Unicode code ) and String.fromCharCode(Unicode code ): take Unicode Code to character
String.fromCodePoint() Can identify greater than 0xffff Code point character , and String.fromCharCode() Cannot identify greater than 0xffff The characters of
String.fromCodePoint(0x20BB7) // '𠮷'
String.fromCharCode(0x20BB7) // Abandon the highest position , Go straight back to 0xBB7 Corresponding characters -> 'ஷ'
String.formCodePoint() <--- Characters and Code points Cross conversion --> ' character '.codePointAt()
String.fromCharCodde() <--- Characters and Code points Cross conversion --> ' character '.charCodeAt()
2、‘ character ’.codePointAt() and ‘ character ’.charCodeAt(): Convert characters to decimal code points , If you want hexadecimal code points, you can use toString(16) Switch down
‘ character ’.codePointAt() Four byte characters can be recognized , and ‘ character ’.charCodeAt() Only two byte characters can be recognized
'𠮷'.codePointAt().toString(16) // 0x20BB7
'𠮷'.charCodeAt().toString(16) // d842
3、String.raw character : Will translate the characters that need to be translated \ Translate again
String.raw`\\ndasdasa` // return \\\\ndasdasa
4、‘Unicode character ’.normallize() Method : It is used to unify different representations of the same character , namely Unicode Normalization of
'\u01D1'.normalize() === '\u004F\u030C'.normalize() // \u01D1 and \u004F\u030C Both represent the same characters
5、includes()、startsWith()、endsWith(): Determine whether a character contains a character
'asdfrew345'.includes('fre') // true --> 'asdfrew345' Does it include ’fre‘
'asdfrew345'.includes('aaa') // false --> 'asdfrew345' Does it include ’aaa‘
'asdfrew345'.startsWith('fre') // false --> 'asdfrew345' Is the front of ’fre‘
'asdfrew345'.startsWith('asd') // true --> 'asdfrew345' Is the front of ’asd‘
'asdfrew345'.startsWith('fre') // false --> 'asdfrew345' Whether the tail of is ’fre‘
'asdfrew345'.startsWith('345') // true --> 'asdfrew345' Whether the tail of is ’345‘
6、‘ character ’.repeat(n): Copy the original character n Time
'a'.repeat(Infinity) // RangeError ---> Less than 0 Will report a mistake
'a'.repeat(-2) // RangeError ---> Less than 0 Will report a mistake
'a'.repeat(-1.4) // RangeError ---> Less than 0 Will report a mistake
'a'.repeat(NaN) // ''
'a'.repeat(-0.6) // '' ---> -1~0 Between Will return to empty
'a'.repeat(3.2) // 'aaa' ---> Ignore decimals , Integer
'a'.repeat(2) // 'aa'
7、padStart()、padEnd(): Completion of string
'ab'.padStart(5, 'xy') // 'xyxab' In string 'ab' Head complement 'xy', The total length of 5
'ab'.padStart(5) // ' ab' In string 'ab' The header of the default fill empty characters '', The total length of 5
'abwew'.padStart(5, 'xy') // 'abwew'
'ab'.padEnd(5, 'xy') // 'abxyx' In string 'ab' Tail completion of 'xy', The total length of 5
'ab'.padEnd(5) // 'ab ' In string 'ab' The default completion of the tail of empty characters '', The total length of 5
'abwew'.padEnd(5, 'xy') // 'abwew'
8、trim()、trimStart()、trimEnd()、trimLeft()、trimRight(): Eliminate string spaces
' aa da '.trim() // Eliminate all spaces at the beginning and end of the string --- > 'aa da'
' aa da '.trimStart() // Eliminate all spaces in the string header --- > 'aa da '
' aa da '.trimLeft() // Eliminate all spaces in the string header --- > 'aa da '
' aa da '.trimEnd() // Eliminate all spaces at the end of the string --- > ' aa da'
' aa da '.trimRight() // Eliminate all spaces at the end of the string --- > ' aa da'
9、‘ character ’.replace() and ' character ’replaceAll(); Replace some characters in the characters
// Replace the first character from left to right in the string 'a' by '-'
'aagafewrqw'.replace('a', '-') // '-agafewrqw'
// Replace all characters in the string 'a' by '-'
'aagafewrqw'.replace(/a/g, '-') // '--g-fewrqw'
// Replace the first character from left to right in the string ( Case insensitive ) 'a' by '-'
'Aagafewrqw'.replace(/a/i, '-') // '-agafewrqw'
// Replace all characters in the string 'a' by '-'
'aagafewrqw'.replaceAll('a', '-') // '--g-fewrqw'
// The second argument can be a function
'aabbcc'.replaceAll('b', () => '_') // 'aa__cc'
// $& Represents the matching string itself , namely `b` In itself , So the returned result is consistent with the original string
'abbc'.replaceAll('b', '$&') // 'abbc'
// $` Represents the string before the matching result , For the first `b`,$` Refer to `a`, For the second `b`,$` Refer to `ab`
'abbc'.replaceAll('b', '$`') // 'aaabc'
// $' Represents the string after the matching result , For the first `b`,$' Refer to `bc`, For the second `b`,$' Refer to `c`
'abbc'.replaceAll('b', `$'`) // 'abccc'
// $1 Represents the first group match of a regular expression , Refer to `ab`,$2 Represents the second group match of regular expressions , Refer to `bc`
'abbc'.replaceAll(/(ab)(bc)/g, '$2$1') // 'bcab'
// $$ Refer to Dollar symbol $
'abc'.replaceAll('b', '$$') // 'a$c'
const str = 'aa123abc456aa', regex = /(\d+)([a-z]+)(\d+)/g;
function replacer(match, p1, p2, p3, offset, string) {
console.log(match) // Matching content ---》 123abc456
console.log(p1) // Group 1 ---》 123
console.log(p2) // Group 2 ---》 abc
console.log(p3) // Group 3 ---》 456
console.log(offset) // The location of the matching content ---》 0
console.log(string) // Full string ---》 aa123abc456aa
return [p1, p2, p3].join(' - ');
}
str.replaceAll(regex, replacer) // aa123 - abc - 456aa
10、‘ character ’.at( Indexes ): Gets the character at the specified position
'das'.at(-1) // 's'
'das'.at(-2) // 'a'
'das'.at(-3) // 'd'
'das'.at(-4) // undefined
'das'.at(666) // undefined
'das'.at(2) // 's'
'das'.at(1) // 'a'
'das'.at(0) // 'd'
'das'.at(true) // 'a'
'das'.at(false) // 'd'
'das'.at(NaN) // 'd'
'das'.at('fafdafdafdsafa') // 'd'
That's the record , I wish you all happiness ~
边栏推荐
- Ubuntu20.04 PostgreSQL 14 installation configuration record
- [IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me
- Basic number theory -- Gauss elimination
- [eight sorts ④] merge sort, sort not based on comparison (count sort, cardinal sort, bucket sort)
- [eight sorts ①] insert sort (direct insert sort, Hill sort)
- We should make clear the branch prediction
- Error creating bean with name ‘stringRedisTemplate‘ defined in class path re
- No converter found for return value of type: class
- I'll teach you to visit Amazon RDS for a year and build a MySQL cloud database (only 10 minutes, really fragrant)
- [image enhancement] vascular image enhancement based on frangi filter with matlab code
猜你喜欢

6-3 vulnerability exploitation SSH environment construction
![[IVX junior engineer training course 10 papers] 05 canvas and aircraft war game production](/img/dc/e9adb1b41c2175c6f18d8027e0530a.jpg)
[IVX junior engineer training course 10 papers] 05 canvas and aircraft war game production

Iclr2022 | spherenet and g-spherenet: autoregressive flow model for 3D molecular graph representation and molecular geometry generation
![[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me](/img/b8/31a498c89cf96567640677e859df4e.jpg)
[IVX junior engineer training course 10 papers] 04 canvas and a group photo of IVX and me

6-2漏洞利用-ftp不可避免的问题

SAP ui5 beginner tutorial XXI - trial version of custom formatter of SAP ui5

XMIND mind map

Sql--- related transactions

2022年6月国产数据库大事记

Learn C language from scratch day 025 (maze)
随机推荐
What are the differences between software testers with a monthly salary of 7K and 25K? Leaders look up to you when they master it
教你白嫖Amazon rds一年并搭建MySQL云数据库(只需10分钟,真香)
Datawhale community blackboard newspaper (issue 1)
MySQL application day02
笔者更加愿意将产业互联网看成是一个比消费互联网要丰富得多的概念
Keepalived introduction and installation
No converter found for return value of type: class
CEPH buffer yyds dry inventory
SQL injection for Web Security (2)
[IVX junior engineer training course 10 papers] 02 numerical binding and adaptive website production
ACM教程 - 快速排序(常规 + 尾递归 + 随机基准数)
技术大佬准备就绪,话题C位由你决定
Geek DIY open source solution sharing - digital amplitude frequency equalization power amplifier design (practical embedded electronic design works, comprehensive practice of software and hardware)
Han Zhichao: real time risk control practice of eBay based on graph neural network
学习笔记25--多传感器前融合技术
We should make clear the branch prediction
[dynamic planning] interval dp:p3205 Chorus
Based on Simulink and FlightGear, the dynamic control of multi rotor UAV in equilibrium is modeled and simulated
Basic number theory -- Gauss elimination
[eight sorts ④] merge sort, sort not based on comparison (count sort, cardinal sort, bucket sort)