当前位置:网站首页>The problem of removing spaces from strings
The problem of removing spaces from strings
2022-04-23 02:41:00 【An effort to XX program yuan】
Have a headache , I can't figure out what this space is , character string str=“123 48 454878”, Want to get only numbers , Usage method str.replace(" “,”"); The result is “123 48454878”, Aren't those two lumps in front of you blank spaces ?
In regular expressions ,\s Matches any whitespace characters , Including Spaces 、 tabs 、 Page breaks and so on . Equivalent to [ \f\n\r\t\v]. But this space doesn't match \s. as follows :
String str = "123 48 454878";
System.out.println(str.replaceAll("\\s", ""));// The result is 123 48454878, It's just removed 8 and 4 Space between
Only later did I know , Spaces and others :
1. Continuous space \u00A0, Mainly used in office in , Let a word not wrap at the end , Shortcut key ctrl+shift+space ;
2. Half space ( English symbols )\u0020, Commonly used in code ;
3. Full space ( Chinese symbols )\u3000, Use... In Chinese articles .
Use Transformation tool , Copy the space above into , The result is converted to \u3000, So modify the code :
String str = "123 48 454878";
System.out.println(str.replaceAll("\\u3000", "").replaceAll("\\s", ""));// The result is 12348454878
版权声明
本文为[An effort to XX program yuan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230239165785.html
边栏推荐
- How to solve the complexity of project document management?
- OCR识别PDF文件
- Real math problems in 1958 college entrance examination
- WordPress calls the specified page content. 2 get_ children()
- MySQL / SQL Server判断表或临时表存在则删除
- hack the box optimum靶机
- SO库依赖问题
- MySQL复杂查询使用临时表/with as(类似表变量)
- How to recognize products from the perspective of Dialectics
- Halo open source project learning (I): project launch
猜你喜欢
接口请求时间太长,jstack观察锁持有情况
Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad
【2019-CVPR-3D人体姿态估计】Fast and Robust Multi-Person 3D Pose Estimation from Multiple Views
每日一题冲刺大厂第十六天 NOIP普及组 三国游戏
Interpretation of the future development of smart agriculture
Fashion MNIST dataset classification training
Practical combat of industrial defect detection project (II) -- steel surface defect detection based on deep learning framework yolov5
JVM class loader
Efficient music format conversion tool Music Converter Pro
Devil cold rice 𞓜 078 devil answers the market in Shanghai and Nanjing; Communication and guidance; Winning the country and killing and screening; The purpose of making money; Change other people's op
随机推荐
Class initialization and instance initialization interview questions
5W of knowledge points
[XJTU计算机网络安全与管理]第二讲 密码技术
【2019-CVPR-3D人体姿态估计】Fast and Robust Multi-Person 3D Pose Estimation from Multiple Views
接口请求时间太长,jstack观察锁持有情况
工业互联网+危化安全生产综合管理平台怎样建
win查看端口占用 命令行
JZ22 链表中倒数最后k个结点
The second day of learning rhcsa
Yes, from today on, our fans can participate in Netease data analysis training camp for free!
Global, exclusive, local Routing Guard
Flink stream processing engine system learning (II)
能做多大的单片机项目程序开发,就代表了你的敲代码的水平
windows MySQL8 zip安装
Machine learning (Zhou Zhihua) Chapter 14 probability graph model
Halo open source project learning (I): project launch
牛客手速月赛 48 C(差分都玩不明白了属于是)
C # import details
hack the box optimum靶机
[suggestion collection] hematemesis sorting out golang interview dry goods 21 questions - hanging interviewer-1