[英]How to remove the \n, \t and spaces between the strings in java?
如何删除java中字符串之间的\\ n,\\ t和空格?
str.replaceAll("\\s+", "");
\\s A whitespace character: [ \\t\\n\\x0B\\f\\r]
\\ s一个空格字符:[\\ t \\ n \\ x0B \\ f \\ r \\ n]
java.util.regex.Pattern
has all the predefined classes. java.util.regex.Pattern
具有所有预定义的类。
将String.replaceAll与正则表达式一起使用以删除所有空格:
s = s.replaceAll("\\s+", "");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.