Removing whitespace from strings in Java

前端 未结 30 2205
一个人的身影
一个人的身影 2020-11-22 05:01

I have a string like this:

mysz = \"name=john age=13 year=2001\";

I want to remove the whitespaces in the string. I tried trim()

30条回答
  •  温柔的废话
    2020-11-22 05:32

    String a="string with                multi spaces ";
    //or this 
    String b= a.replaceAll("\\s+"," ");
    String c= a.replace("    "," ").replace("   "," ").replace("  "," ").replace("   "," ").replace("  "," ");
    

    //it work fine with any spaces *don't forget space in sting b

提交回复
热议问题