1

I'm trying to remove white space in a String, adressString (see below).

enter image description here

To do so, I'm using the folowing piece of code :

adressString.replaceAll("\r","");

However, this does not work : I'm stil having this whitespace (see below) :

enter image description here

Solution :

I needed to declare another String :

String adressWithoutCarriageReturn = adressString.replaceAll("\r", "");

tcacciatore
  • 462
  • 6
  • 20

2 Answers2

1

Just add one more slash like below:

adressString.replaceAll("\\r","");

As "\" is a special character.

hpopiolkiewicz
  • 2,702
  • 3
  • 22
  • 36
Sagar Maiyad
  • 12,482
  • 8
  • 60
  • 97
1

Y can't we use it like below.

String a =  str.replace(" ","");
Jens
  • 63,364
  • 15
  • 92
  • 104
user1111880
  • 403
  • 4
  • 8
  • 23