试图删除空格和下划线后的所有首字母应该是字符串中的大写字母,但不起作用。如何在角度8中操作。如果有人知道,请帮助我找到解决方案。
app.component.ts:
let content="power_managment 0vol";
alert(content.split( ).[0]);
// output should be like "powerManagment"
尝试使用slice
和indexOf
功能
let content="power_managment 0vol";
content = content.slice(0, content.indexOf(' '));
我认为您想要这样的东西:
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]))
let content="power_managment 0vol ";
let trimmedContent = content.trim()