Hi I am trying to split json string using possibly pipe? or I don't really know how to do it.
Right now I have json string of
"www.youtube.com||djlajdalksd.png||somethingsomething"
(These are just made up)
And I want to only get .png part.
How could I achieve this?
解决方案
Write a pipe:
@Pipe({ name: "splitAndGet" })
export class SplitAndGetPipe implements PipeTransform {
transform(input: string, separator: string,index:number): string {
return input.split(separator)[index];
}
}
then in template:
{{"www.youtube.com||djlajdalksd.png||somethingsomething"|splitAndGet:"||":1}}
that will return "djlajdalksd.png"