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
  • 483
  • 6
  • 21

2 Answers2

1

Just add one more slash like below:

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

As "\" is a special character.

hpopiolkiewicz
  • 3,281
  • 4
  • 24
  • 36
Sagar Maiyad
  • 12,655
  • 9
  • 63
  • 99
1

Y can't we use it like below.

String a =  str.replace(" ","");
Jens
  • 67,715
  • 15
  • 98
  • 113
user1111880
  • 443
  • 5
  • 8
  • 26