Tal*_*ode 17 trim typescript angular
在我的angular 5项目中,使用typescript我在这样的字符串上使用.trim()函数,但它不是删除空格而且也没有给出任何错误.
this.maintabinfo = this.inner_view_data.trim().toLowerCase();
// inner_view_data has this value = "Stone setting"
Run Code Online (Sandbox Code Playgroud)
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-1-4.html本文明确指出,这.trim()是打字稿的一部分.
从typescript中的字符串中删除空格的最佳方法是什么?
Hri*_*ale 32
trim()方法从字符串的两边删除空格.
你可以使用javascript替换方法来删除像
"hello world".replace(/\s/g, "");
Run Code Online (Sandbox Code Playgroud)
trim()方法从字符串的两边删除空格.
要删除字符串中的所有空格使用 .replace(/\s/g, "")
this.maintabinfo = this.inner_view_data.replace(/\s/g, "").toLowerCase();
Run Code Online (Sandbox Code Playgroud)
Trim 只是删除尾随和前导空格。如果只有空格要替换,请使用 .replace(//g, "")。
this.maintabinfo = this.inner_view_data.replace(/ /g, "").toLowerCase();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
52980 次 |
| 最近记录: |