当前位置:网站首页>Concatenate the specified character at the end of a number in a string
Concatenate the specified character at the end of a number in a string
2022-06-22 08:01:00 【xiaoke815】
I'm working on a project for the hospital , The doctor asked that all the units at the end of the number be spliced , such as "(4)9*&5MM)8999)3&4*9*[email protected]" The numbers in this string of words are spliced with a unit at the end , become (4°)9°*&5°MM)8999°)3°&4°*9°*2°@, My code is shown in the figure below :

code snippet :
/**
* Number end splice ° Symbol
*/
public static String appendDegreeMark(String content) {
int lastEndIndex = 0;
Matcher matcher = pattern.matcher(content);
StringBuilder stringBuilder = new StringBuilder();
while (matcher.find()) {
int startIndex = matcher.start(0);
if (lastEndIndex != startIndex) {
String preContent = content.substring(lastEndIndex, startIndex);
stringBuilder.append(preContent); // Splices non numeric text between the end of the last number and the start of the current matching number
}
stringBuilder.append(matcher.group(0)).append("°");// Splice units
lastEndIndex = matcher.end(0);// Starting position of the next round
}
// If the starting position of the next round is equal to the length of the text, it means that all the text has been spliced , Otherwise, splice the remaining text
if (lastEndIndex < content.length()) {
String lastStr = content.substring(lastEndIndex ,content.length());
stringBuilder.append(lastStr);
}
return stringBuilder.toString();
}边栏推荐
- Baidu Post Bar crawler crawls to the middle of the building
- AutoCAD 2020.3 Chinese Version (old version)
- Fmdb usage details mark
- 【Oracle 数据库】奶妈式教程day15 DDL、DML、索引、视图、序列、死锁这一篇就够了
- MySQL backup - mysqldump
- Use of keepalived high availability cluster
- .net core 技术栈 网站收集
- QT QtableView的使用示例
- MySQL transactions
- Microsoft Remote Desktop 10.7.6 official
猜你喜欢

面试突击59:一个表中可以有多个自增列吗?

Use of keepalived high availability cluster

MySQL transactions

Skills required for O & M automation?

Stored procedures and functions of MySQL

Microsoft Remote Desktop 10.7.6 official

Xmind 2022思维导图激活版资源?

Upload your own library to pod

Target detection series -- detailed explanation of RCNN principle

【Oracle 数据库】奶妈式教程 day13 日期函数
随机推荐
Oracle execution plan analysis
CollectionViewCell
模电实验——实验二 JFET共源极放大电路
[Oracle database] wet nurse tutorial day15 DDL, DML, index, view, sequence and deadlock are enough
KVO summary
Submit values of various inputs of the form
Upload your own library to pod
MySQL index
Itemtools permutation
Detailed explanation of subnet mask
Node red sends wechat official account message (template message)
Canvastotempfilepath of wechat
easy-rule 初窥
Usage and understanding of async/await in JS
Win openfeign from simple to deep
OSI and tcp/ip
Concurrent programming summary
力扣(LeetCode)172. 阶乘后的零(2022.06.21)
代码覆盖率测试对编程小白的意义及其使用方法
Why redis is so fast: