JavaScript: String.trim() - JavaScripter.net - JavaScript FAQ, quizzes, games, and more

JavaScript: String.trim() - JavaScripter.net - JavaScript FAQ, quizzes, games, and more

瀏覽:1365
日期:2025-06-29
Question: How do I trim leading and trailing spaces of a string? Answer: To remove all leading and trailing spaces from a string str, you can use this code: str = str.replace(/^\s+|\s+$/g,'') This code example uses the regular expression /^\s+...看更多