Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Android deleted all spaces in the string.
Android deleted all spaces in the string.
In the process of developing a project, it is sometimes necessary to transfer data to the server when requesting an interface. The data you enter in the input box may have spaces, which may be at the beginning and end of the string or in the middle of the string, and must be removed. We can remove spaces in the following ways.

Delete leading and trailing spaces -trim ():

str.getText()。 toString()。 trim();

Delete all spaces -replaceAll ("","");

str.getText()。 toString()。 replaceAll(" "," ");