当前位置:网站首页>Dart: string replace related methods to solve replacement characters
Dart: string replace related methods to solve replacement characters
2022-06-30 16:18:00 【Hua Weiyun】
About String Some operations on this aspect in .
replaceAll
String replaceAll(pattern from,String replace)
replaceAll The first parameter is the matcher , It can be a string or a regular expression , The second parameter is the string to replace , The return value is a new string .
, I'm here to write a Demo, As you all know
void main() { var a = ' Big front end ️ The journey ️'; var b = ' Big front end ️'; print(a.replaceAll('️', '')); print(b.replaceAll(RegExp(r'(️)'), '')); }
The operation effect is as follows :
Have you learned the above
Let's go on
replaceAllMapped
String replaceAllMapped(Pattern from,String replace(Match match))
replaceAllMapped The first parameter is the matcher , It can be a string or a regular , The second argument is a function , The string fragment captured by the parameter of the function , In fact, it is a mapping of the captured string fragments , Look at the function name mapped You can see .
void main() { var a = ' Big front end ️ The journey ️'; var b = ' Big front end ️'; print(a.replaceAllMapped('️', (Match m) => '')); print(b.replaceAllMapped(RegExp(r'️'), (Match m) => '')); }
replaceFirst
String replaceFirst(Pattern from,String to,[int startIndex = 0])
replaceFirst The first parameter is the match character , It can be a string or a regular , The second parameter is the string to replace , The third parameter is optional , The default is 0,. If this method matches multiple string fragments , Then it will only replace the subscript startIndex The capture of , If the subscript is larger than the length of the captured fragment , Then there will be an error
void main() { var d = ' Big front end tour '; print(d.replaceFirst(RegExp(r'\ Big '), 'jianguo', 0)); //1ccc3}
4.replaceFirstMapped
String replaceFirstMapped(Pattern from,String replace(Match match),[int startIndex = 0])
replaceFirstMapped and replaceAllMapped similar , Replace the captured string fragment startIdnex The corresponding segment , And through the function passed by the second parameter .
var e = 'asd'; print(e.replaceFirstMapped(RegExp(r'\w'), (Match m) => '${m[0]}${m[0]}', 2),);//asdd
5.replaceRange
String replaceRange(int start,int end,String replacement)
replaceRange The first parameter is the starting subscript , The second parameter is the ending subscript , The third parameter is the string to replace . The replaced string contains the starting subscript , Does not include end subscript , And start subscribing numbers to >=0, Less than or equal to the end subscript , The value of the end subscript must be less than or equal to the length of the string , Otherwise, an error will be reported .
var f = '123456789'; print(f.replaceRange(1, 3, 'replace')); //1replace456789
The above is what I use replace Some related operations ,
In the project, I also used this line of code to solve the problem .
边栏推荐
- Kindle down, ireader relay
- Types of waveguides
- What is XR extended reality and what are the XR cloud streaming platforms
- Two methods for MySQL to open remote connection permission
- Google Play 索引表
- Go micro installation
- CloudXR如何推动XR的未来发展
- String common API
- mysql8报错:ERROR 1410 (42000): You are not allowed to create a user with GRANT解决办法
- mysql主从配置
猜你喜欢
大学生研究生毕业找工作,该选择哪个方向?
19:00 p.m. tonight, knowledge empowerment phase 2 live broadcast - control panel interface design of openharmony smart home project
How cloudxr promotes the future development of XR
Visualization of provincial GDP with CSV metabase processing
ASP. Send information in sinalr controller of net core
Simulation of two-color ball system to judge the winning situation
Map reduce case super detailed explanation
Policy Center-User Data
Using asp Net core creating web API series
Google play index table
随机推荐
Policy Center > Device and Network Abuse
服务端测试工程师面试经验
mysql主从配置
Mysql8 error: error 1410 (42000): you are not allowed to create a user with grant solution
[time series database incluxdb] code example for configuring incluxdb+ data visualization and simple operation with C under Windows Environment
Open source STM32 USB-CAN project
mysql8报错:ERROR 1410 (42000): You are not allowed to create a user with GRANT解决办法
Google play index table
Compare whether the two arrays are the same
Implementation of Devops in the core field of qunar, the Internet R & D Efficiency
Solution for IIS failing to load font files (*.woff, *.svg)
Policy Center > Malware > Malware
有意思的鼠标指针交互探究
Modifying MySQL password under Linux: error 1396 (HY000): Operation alter user failed for 'root' @ 'localhost‘
IIS无法加载字体文件(*.woff,*.svg)的解决办法
Generating verification code with sring
《你的灯亮着吗》开始解决问题前,得先知道“真问题”是什么
Warning: [antd: Menu] `children` will be removed in next major version. Please use `items` instead.
Using asp Net core creating web API series
云化XR,如何助力产业升级