Angular2 如何拆分字符串?

标签 angular split

您好,我正在尝试使用可能的管道拆分 json 字符串吗?或者我真的不知道该怎么做。

现在我有

"www.youtube.com||djlajdalksd.png||somethingsomething"

的 json 字符串 (这些都是编的)

我只想得到 .png 部分。

我怎样才能做到这一点?

最佳答案

写一个管道:

@Pipe({ name: "splitAndGet" })
export class SplitAndGetPipe implements PipeTransform {
  transform(input: string, separator: string,index:number): string {
    return input.split(separator)[index];
  }
}

然后在模板中:

{{"www.youtube.com||djlajdalksd.png||somethingsomething"|splitAndGet:"||":1}}

这将返回 "djlajdalksd.png"

关于Angular2 如何拆分字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43224957/

相关文章:

javascript - 在提交表单上显示模态

matlab - 按分隔符拆分为整数数组的字符串元胞数组

angular - 将查询参数与 @ngrx/router-store 合并

angular - 日期选择器的国际化

angular - 获取 Angular 2 中的 mdslider 值?

angular - RxJS subscribe() 函数内的组件变量未定义

arrays - 算法将数组拆分为子数组,其中所有子数组之间的最大总和尽可能低

python - 在Python中使用Split()从字符串中提取所有引号

Python 正则表达式 : Splitting by\n character as long as the\n isn't at the start

c#用“异常分割字符串