java去除字符串中的空格、回车、换行符、制表符
2024-10-15 09:23:40
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author chzeze
* 2016-11-07
*/
public class StringUtils {
public static String replaceBlank(String str) {
String dest = "";
if (str != null) {
Pattern p = Pattern.compile("\\s*|\t|\r|\n");
Matcher m = p.matcher(str);
dest = m.replaceAll("");
}
return dest;
}
public static void main(String[] args) {
System.out.println(StringUtils.replaceBlank("just do it!"));
}
/*----------------------------------- 笨方法:String s = "你要去除的字符串"; 1.去除空格:s = s.replace('\\s',''); 2.去除回车:s = s.replace('\n',''); 这样也可以把空格和回车去掉,其他也可以照这样做。 注:\n 回车(\u000a)
\t 水平制表符(\u0009)
\s 空格(\u0008)
\r 换行(\u000d)*/
}
最新文章
- 2016百度之星 资格赛ABCDE
- Magento显示多货币,Magento 多货币设置
- ubuntu 安装 netbeans C++ IDE
- mysql 定义自增
- git checkout 命令详解
- iOS小技巧3
- SSIS hang with unhandle exception
- 使用soapui调用webservice接口
- python数据分析师面试题选
- maven配置开发
- C++ STL算法系列1---count函数
- S2 结业考试前改错汇总
- linkin大话面向对象--封装和隐藏
- 黑盒测试实践——day03
- SD卡与FAT32系统学习
- Spring MVC 注解 @RequestParam解析
- 【Linux】war包的解压与压缩
- CSS小技巧(一)
- MySQL 数据类型总结及选取准则
- jQuery实现清空table表格除首行外的所有数据