1
response1 = CustomHttpClient.executeHttpPost("http://gamesdsxd.com/appfiles/login.php", postParameters);
String res = response1.toString();
res = res.replaceAll("\\s+", "");

I'm wondering what \s+ does and what this replaceAll does and why it is needed.

Drake
  • 95
  • 1
  • 6
  • 2
    Just click your way through the javadoc: http://download.oracle.com/javase/6/docs/api/java/lang/String.html#replaceAll%28java.lang.String,%20java.lang.String%29 – BalusC Aug 27 '11 at 04:38
  • http://stackoverflow.com/questions/5429330/how-to-send-data-from-java-servlet-to-android-client – Book Of Zeus Aug 27 '11 at 04:38

4 Answers4

4

The \s+ replaces all occurrences of a space " " with no space "".

For more help, see this link: Removing Whitespace Between String.

Dan W
  • 5,718
  • 4
  • 33
  • 44
2

Here is what replaceAll will do with a small example:

String str = "This5is5testing5of5replaceAll";
        str = str.replaceAll("5", " ");
        System.out.println(str);

Here the output will be: This is testing of replaceAll

5 will be replaced by space everywhere.

halfer
  • 19,824
  • 17
  • 99
  • 186
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
1

\s+ is a regular expression. It matches strings which consist of at least one white space character. \s is actually a meta character. Here it is removing white space.

Here is the replaceAll documentation.

replaceAll(String regex, String replacement) Replaces each substring of this string that matches the given regular expression with the given replacement

Adnan Bhatti
  • 3,410
  • 4
  • 25
  • 38
0

it replaces double spaces or more to no space. For example: " " will transform into ""; " " will transform into ""; but " " will still be equal to " ".