EditText recEmail=(EditText)findViewbyId(R.id.email);
EditText recPassword=(EditText)findViewbyId(R.id.password);
String email=recEmail.getText().toString();
String password=recPassword.getText().toString();
The email and password contains the white spaces at start,in or end of string if tab is pressed by mistake.
I need text out of white spaces, please help if you can.
Thanks in advance....!!!
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With