当前位置:网站首页>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
边栏推荐
- Go语言web中间件的使用
- RT_Thread自问自答
- JDBC JDBC
- 类初始化和实例初始化面试题
- JVM运行时数据区(一)
- 【unity3D】直播间滚动式弹幕效果
- The second day of learning rhcsa
- Interim summary (Introduction + application layer + transportation layer)
- The usage and difference of * and & in C language and the meaning of keywords static and volatile
- IAR embedded development stm32f103c8t6 Lighting LED
猜你喜欢

Machine learning (Zhou Zhihua) Chapter 14 probability graph model
![[wechat applet] set the bottom menu (tabbar) for the applet](/img/e2/98711dfb1350599cbdbdf13508b84f.png)
[wechat applet] set the bottom menu (tabbar) for the applet
智能辅助功能丰富,思皓X6安全配置曝光:将于4月23日预售

Using go language to build web server

【unity3D】直播间滚动式弹幕效果

leangoo脑图-共享式多人协作思维导图工具分享
![Parental delegation model [understanding]](/img/ba/07e280a2634018e0d6b56c05dd3bc0.png)
Parental delegation model [understanding]

期中汇总(概论+应用层+运输层)

全局、独享、局部路由守卫

Practice of industrial defect detection project (III) -- Based on FPN_ PCB defect detection of tensorflow
随机推荐
Rhcsa second day operation
Rich intelligent auxiliary functions and exposure of Sihao X6 security configuration: it will be pre sold on April 23
JZ22 鏈錶中倒數最後k個結點
期中汇总(概论+应用层+运输层)
Preliminary understanding of stack and queue
Flink learning (XI) watermark
TypeScript(1)
Classification and regression tree of machine learning
C语言 171. 最近回文数
Day 4 of learning rhcsa
Target narak
WordPress calls the specified page content. 2 get_ children()
Store consumption SMS notification template
1215_ Hello world used by scons
使用Go语言构建Web服务器
Practice of industrial defect detection project (III) -- Based on FPN_ PCB defect detection of tensorflow
Fashion MNIST 数据集分类训练
Water diversion into chengluo Valley p1514
打靶narak
Implementation of distributed scenario business operation log (based on redis lightweight)