Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
72
rated 0 times [  77] [ 5]  / answers: 1 / hits: 20871  / 6 Years ago, sat, october 6, 2018, 12:00:00

Let's say I get a string with special characters and I want to use filter/pipe to change it. Also the first letter of each word should be uppercase.



For example @!₪ test stri&!ng₪ will become Test String.



How can that be done?


More From » angular

 Answers
19

You can do with a pipe as follows,



import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'specialPipe'
})
export class specialPipe implements PipeTransform {

transform(value: string): string {
let newVal = value.replace(/[^ws]/gi, '')
return newVal.charAt(1).toUpperCase() + newVal.slice(2);
}

}


DEMO STACKBLITZ


[#53361] Tuesday, October 2, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
adrienkeithr

Total Points: 503
Total Questions: 126
Total Answers: 110

Location: Lithuania
Member since Fri, Sep 4, 2020
4 Years ago
;