Home > Java > JavaBase > Detailed explanation of trim() method in java

Detailed explanation of trim() method in java

hzc
Release: 2020-06-22 17:40:27
Original
7308 people have browsed it

Detailed explanation of trim() method in java

Detailed explanation of trim() method in java: The role of

trim() It is to remove the extra spaces at both ends of the string. Note that it is the spaces at both ends, and it will be removed no matter how many spaces there are at both ends. Of course, the spaces in the middle of

will not be removed, such as:

String s = " a s f g ";

String s1 = s.trim();

Then s1 is "a s f g", visible , which is the same as what was said above.

trim() can not only remove spaces, but also remove some other redundant symbols. These symbols are:

\t \n \v \ f \r \x0085 \x00a0 ? \u2028 \u2029

is translated as: horizontal tab character, line feed character, vertical tab character, page feed character, carriage return, and the following few Except for the question mark, everything else is written in the form of escape characters.

Extended information:

trim()The function removes blank characters or other predefined characters on both sides of a string.

Function removes spaces or other characters at the beginning and end of a string. When the function is successfully executed, it returns a string with the leading and trailing spaces of string removed. When an error occurs, it returns an empty string (""). If the value of any parameter is NULL, the Trim() function returns NULL.

Recommended tutorial: "java tutorial"

The above is the detailed content of Detailed explanation of trim() method in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template