Hey everyone, I have a pipe that currently returns each word with the first letter uppercase and the rest lowercase. It also removes any non-English characters from the value. I'm trying to figure out how to add the ':' character so it will be included in the output instead of being removed. Any ideas on how to achieve this?
Current Example:
@# test: me #@
Output:
Test Me
Desired Output:
Test: Me
Please see my code below:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'special'
})
export class SpecialPipe implements PipeTransform {
transform(value: string): string {
let newVal = value.replace(/[^\w\s]/gi, '').toLocaleLowerCase();
return this.titleCase(newVal);
}
titleCase(str) {
var splitStr = str.toLowerCase().split(' ');
for (let i = 0; i < splitStr.length; i++) {
splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);
}
return splitStr.join(' ');
}
}