简体   繁体   English

.replaceAll(“\\s+$”,“”); 有什么用?

[英]What is use of .replaceAll(“\\s+$”,“”);

Please anyone tell me what is the difference between:请任何人告诉我有什么区别:

  1. .replaceAll("\\s","");
  2. .replaceAll("\\s+","");
  3. and .replaceAll("\\s+$","");.replaceAll("\\s+$","");

s.replaceAll("\\s", "") Replace each space character with nothing. s.replaceAll("\\s", "")将每个空格字符替换为空。

s.replaceAll("\\s+", "") Replace each group of 1 or more spaces with nothing. s.replaceAll("\\s+", "")将每组 1 个或多个空格替换为空。

s.replaceAll("\\s+$", "") Replace each group of 1 or more spaces at the end of the string with nothing. s.replaceAll("\\s+$", "")将字符串末尾的每组 1 个或多个空格替换为空。

All of these special characters are explained well in the javadoc.所有这些特殊字符在 javadoc 中都有很好的解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM