How to remove the \n, \t and spaces between the strings in java?

前端 未结 2 461
鱼传尺愫
鱼传尺愫 2020-12-21 10:08

How do you remove the \\n, \\t and spaces between strings in java?

相关标签:
2条回答
  • 2020-12-21 10:26
    str.replaceAll("\\s+", "");
    

    \s A whitespace character: [ \t\n\x0B\f\r]

    java.util.regex.Pattern has all the predefined classes.

    0 讨论(0)
  • 2020-12-21 10:37

    Use String.replaceAll with a regular expression to remove all whitespace:

    s = s.replaceAll("\\s+", "");
    
    0 讨论(0)
提交回复
热议问题