Nila Vaani
Nila Vaani

Reputation: 213

How to remove all after space from string in angular 8

Tried to remove all after space and after underscore first letter should be caps from a string but not working.How do it in angular 8.If anyone know please help me to find a solution.

app.component.ts:

let content="power_managment 0vol";
alert(content.split( ).[0]);
// output should be like "powerManagment"

Upvotes: 0

Views: 1071

Answers (3)

ROOT
ROOT

Reputation: 11622

I think you want something like this:

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]))

Upvotes: 1

Mridul
Mridul

Reputation: 1366

Try using slice and indexOf function

let content="power_managment 0vol";
content = content.slice(0, content.indexOf(' '));

Upvotes: 1

Dan T.
Dan T.

Reputation: 425

let content="power_managment 0vol    ";
let trimmedContent = content.trim()

Upvotes: -1

Related Questions