# Refactor multiple replace statements

**URL:** https://discourse.gohugo.io/t/refactor-multiple-replace-statements/9994
**Category:** support
**Created:** [January 14, 2018, 12:59am UTC](https://discourse.gohugo.io/t/refactor-multiple-replace-statements/9994 "2018-01-14T00:59:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![runhide](https://avatars.discourse-cdn.com/v4/letter/r/eada6e/32.png) [@runhide](https://discourse.gohugo.io/u/runhide)
#### Post date: [January 14, 2018, 12:59am UTC](https://discourse.gohugo.io/t/refactor-multiple-replace-statements/9994/1 "2018-01-14T00:59:57Z")

</div>

With the following code, is there a way to do this more neatly instead of using multiple replace statements?

```
{{$a := delimit .Params.products ", "}}
{{$a := replace $a "A, " ""}}
{{$a := replace $a "B, " ""}}
{{$a := replace $a ", C" ""}}
{{$a := replace $a "D, " ""}}
{{$a := split $a ","}}

```

I’ve tried doing the following which works but does not do what I need since it omits the `,`.

```
{{$a := delimit .Params.products ", "}}
{{$b := "A, B, C, D"}}

{{$a := replace $a $b ""}}
{{$a := split $a ","}}

```

If I do something like this I get the error: `can't give argument to non-function "A"`

```
{{$a := delimit .Params.products ", "}}
{{$b := "A, " "B, " ", C" "D, "}}

{{$a := replace $a $b ""}}
{{$a := split $a ","}}
```

---

<div class="post-metadata">

### Author: ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)
#### Post date: [January 14, 2018, 5:25am UTC](https://discourse.gohugo.io/t/refactor-multiple-replace-statements/9994/2 "2018-01-14T05:25:33Z")

</div>

You can pipe them or use replaceRE (if there is a pattern to match), or create a dict first and then replace. See the functions at the Docs.
