How can I eliminate whitespace in a string? How can I put all the characters together and eliminate those spaces?
var incognita = "Hola como estas";
How can I eliminate whitespace in a string? How can I put all the characters together and eliminate those spaces?
var incognita = "Hola como estas";
You can use String.replace () like this:
var incognita = "Hola como estas"
console.log(incognita.replace(/ /g, ""));
If you want to replace from the html this is a way to do it. in this case I use a link HTML:
<a href="/dsoftware/{{item.id_proyecto}}/{{item.nombre | replacepipe}}">Enlace</a>
PIPE (create new file 'replace.pipe.ts'):
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'replacepipe'
})
export class ReplacePipe implements PipeTransform {
transform(value: string): string {
var re = / /gi;
var newstr = value.replace(re, "-");
return newstr;
}
}
MODULE:
import { ReplacePipe } from './replace.pipe';
...
declarations:[AppComponent, ... , ReplacePipe
]