微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

angular – 如何从typescript中的字符串中删除空格?

参见英文答案 > How to remove whitespace in text                                    2个
在我的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中的字符串中删除空格的最佳方法是什么?

解决方法

The trim() method removes whitespace from both sides of a string.

你可以使用javascript替换方法删除

"hello world".replace(/\s/g,"");

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐