hin*_*991 1 javascript pipe typescript angular
假设我得到一个带有特殊字符的字符串,我想使用过滤器/管道来更改它。每个单词的第一个字母也应该大写。
例如"@!? test stri&!ng?"将成为"Test String".
那怎么办呢?
您可以按如下方式使用管道,
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'specialPipe'
})
export class specialPipe implements PipeTransform {
transform(value: string): string {
let newVal = value.replace(/[^\w\s]/gi, '')
return newVal.charAt(1).toUpperCase() + newVal.slice(2);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12815 次 |
| 最近记录: |