Home>Article>Web Front-end> What is the function that can remove both leading and trailing whitespace from a string?

What is the function that can remove both leading and trailing whitespace from a string?

青灯夜游
青灯夜游 Original
2021-01-29 15:55:45 5611browse

The function that can remove leading and trailing whitespace from a string at the same time is: trim(). The trim() function is used to delete the leading and trailing whitespace characters of a string. The whitespace characters include: spaces, tabs, newlines and other whitespace characters; its syntax format is "string.trim()".

What is the function that can remove both leading and trailing whitespace from a string?

The operating environment of this tutorial: Windows 7 system, ECMAScript version 5, Dell G3 computer.

Related recommendations: "javascript video tutorial"

JavaScript trim()

trim() method is used to delete characters The whitespace characters at the beginning and end of the string include: spaces, tabs, newlines and other whitespace characters.

The trim() method does not change the original string.

trim() method is not applicable to null, undefined, Number types.

Syntax

string.trim()

Return value: Returns a string with leading and trailing spaces removed.

Example:

    

点击按钮移除字符串的头尾空格。

For more programming-related knowledge, please visit:Programming Learning! !

The above is the detailed content of What is the function that can remove both leading and trailing whitespace from a string?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:Error object in JavaScript Next article:Error object in JavaScript