[英]Removing a portion of text
I need to remove all the portion of text in square braces along with the braces, in TypeScript. 我需要在TypeScript中删除方括号中所有文本部分。 How can I do this? 我怎样才能做到这一点?
var text="All-Weather Floor Liner Package [installed_msrp]"
You can use the javascript function string.replace 您可以使用javascript函数string.replace
var text="All-Weather Floor Liner Package [installed_msrp]"
var myCleanedStr = text.replace(/(\[.*\])/g, "");
console.log(myCleanedStr); // Output is "All-Weather Floor Liner Package "
You may use a RegExp in conjucation with the replace function. 您可以结合使用RegExp和replace函数。 Like this: 像这样:
'All-Weather Floor Liner Package [installed_msrp]'.replace(/\[.*\]/g, '');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.