在我的 angular 5 项目中,使用 typescript ,我在这样的字符串上使用 .trim() 函数,但它没有删除空格,也没有给出任何错误。
this.maintabinfo = this.inner_view_data.trim().toLowerCase();
// inner_view_data has this value = "Stone setting"
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-1-4.html该文档清楚地表明 .trim()
是 typescript 的一部分。
从 typescript 中的字符串中删除空格的最佳方法是什么?
最佳答案
问题
The trim() method removes whitespace from both sides of a string.
解决方案
您可以使用 Javascript 替换方法来删除像
这样的空格"hello world".replace(/\s/g, "");
例子
var out = "hello world".replace(/\s/g, "");
console.log(out);
关于angular - 如何从 typescript 中的字符串中删除空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49145250/