Remove blank spaces from email and password get by EditText

String.trim() is your friend.

String email=recEmail.getText().toString().trim();
String password=recPassword.getText().toString().trim();

In the future, I highly recommend checking the Java String methods in the API. It's a lifeline to getting the most out of your Java environment.

As a general rule, I would not get rid of whitespace in the text. What if the user's password starts or ends with a space? They will never be able to log in. I personally think you're better off just leaving your code as is.


This is a technically very advanced operation, but can be achieved by extreme coding precision:

mahString = mahString.trim();


try

email.replace(" ", "");
password.replace(" ", "");

to get rid of whitespace throughout the string and email.trim for the ends

Tags:

Java

Android