当前位置:网站首页>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),);//asdd5.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')); //1replace456789The above is what I use replace Some related operations ,
In the project, I also used this line of code to solve the problem .

边栏推荐
- 深入分析GadgetInspector核心代码
- Reptile (1) - Introduction to basic reptile theory
- Solution for IIS failing to load font files (*.woff, *.svg)
- ASP. Net core signalr series hub tutorial
- 开源 STM32 USB-CAN项目
- Mysql事务/锁/日志总结
- Policy Center > Google Play‘s Target API Level Policy
- Log4j2 advanced use
- Cesium-1.72 learning (earth model creation online offline tile)
- [leetcode] linked list sorting (gradually increasing the space-time complexity)
猜你喜欢

开源 STM32 USB-CAN项目

Map reduce case super detailed explanation

Policy Center-User Data

What role does "low code" play in enterprise digital transformation?

Message queue ten questions

“低代码”在企业数字化转型中扮演着什么角色?

'<', hexadecimal value 0x3C, is an invalid 问题解决

CVPR 2022丨特斯联AI提出:基于图采样深度度量学习的可泛化行人重识别

'<', Hexadecimal value 0x3c, is an invalid problem solving
MySQL8.0开启远程连接权限的方法步骤
随机推荐
[time series database incluxdb] code example for configuring incluxdb+ data visualization and simple operation with C under Windows Environment
The inspiration from infant cognitive learning may be the key to the next generation of unsupervised machine learning
Cesium-1.72 learning (earth model creation online offline tile)
【算法篇】四种链表总结完毕,顺手刷了两道面试题
[附下载]渗透测试神器Nessus安装及使用
There are so many kinds of coupons. First distinguish them clearly and then collect the wool!
Hundreds of lines of code to implement a JSON parser
Alibaba cloud OSS object storage cross domain settings
MySQL transaction / lock / log summary
Build cloud native observability capability suitable for organizations
ASP. Net core Middleware
Phone number shielding function
Generating verification code with sring
Explain in detail the use of for loop, break and continue in go language
Table responsive layout tips for super nice
The image variables in the Halcon variable window are not displayed, and it is useless to restart the software and the computer
What is XR extended reality and what are the XR cloud streaming platforms
婴儿认知学习所带来的启发,也许是下一代无监督机器学习的关键
Policy Center > Device and Network Abuse
Asp. NETCORE uses cache and AOP to prevent repeated commit