如何从 angular 8 中的字符串中删除 space 之后的所有内容
How to remove all after space from string in angular 8
试图删除 space 之后和下划线之后的所有首字母应该是字符串的大写字母而不是 working.How 在 angular 8.If 中执行此操作任何人都知道请帮忙我来找解决办法。
app.component.ts:
let content="power_managment 0vol";
alert(content.split( ).[0]);
// output should be like "powerManagment"
let content="power_managment 0vol ";
let trimmedContent = content.trim()
我想你想要这样的东西:
const capitalize = (s) => {
if (typeof s !== 'string') return ''
return s.charAt(0).toUpperCase() + s.slice(1)
}
let content="power_managment 0vol 0vol 0vol 0vol0vol 0vol test 123vol";
let content2 = content.split(" ")[0].split("_");
console.log(content2[0] + "" + capitalize(content2[1]))
尝试使用 slice
和 indexOf
函数
let content="power_managment 0vol";
content = content.slice(0, content.indexOf(' '));
试图删除 space 之后和下划线之后的所有首字母应该是字符串的大写字母而不是 working.How 在 angular 8.If 中执行此操作任何人都知道请帮忙我来找解决办法。
app.component.ts:
let content="power_managment 0vol";
alert(content.split( ).[0]);
// output should be like "powerManagment"
let content="power_managment 0vol ";
let trimmedContent = content.trim()
我想你想要这样的东西:
const capitalize = (s) => {
if (typeof s !== 'string') return ''
return s.charAt(0).toUpperCase() + s.slice(1)
}
let content="power_managment 0vol 0vol 0vol 0vol0vol 0vol test 123vol";
let content2 = content.split(" ")[0].split("_");
console.log(content2[0] + "" + capitalize(content2[1]))
尝试使用 slice
和 indexOf
函数
let content="power_managment 0vol";
content = content.slice(0, content.indexOf(' '));