Removing whitespace from strings in Java

前端 未结 30 2198
一个人的身影
一个人的身影 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:27

    There are others space char too exists in strings.. So space char we may need to replace from strings.

    Ex: NO-BREAK SPACE, THREE-PER-EM SPACE, PUNCTUATION SPACE

    Here is the list of space char http://jkorpela.fi/chars/spaces.html

    So we need to modify

    \u2004 us for THREE-PER-EM SPACE

    s.replaceAll("[\u0020\u2004]","")

提交回复
热议问题