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

标签 angular typescript trim

在我的 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.

Source

解决方案

您可以使用 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/

相关文章:

ios - 快速修剪字符串结尾,在运行时出错

具有可扩展行的 Angular (7+) Material 表 - 同时扩展多个行

Angular 和 AngularFire 5 从文档中检索数据

angular - 无法使用 Video.JS 为 mp4 视频呈现嵌入式字幕

typescript - 关闭接口(interface)的 eslint 规则?

ios - 如何在 iOS 中从开始时间到结束时间修剪或播放音频?

Angular (2+) 组件提供与投影内容的绑定(bind)

typescript - 如何在 TypeScript 3 中正确使用 fromCharCode.apply 和 Uint8Array?

typescript - 减少 Typescript 中的 getter/setter 样板

PHP:从字符串的开头/结尾修剪单词或它的一部分