# Inconsistency between \`replace\` on an \`AbstractString\` vs. \`Vector{Char}\`

**URL:** <https://discourse.julialang.org/t/inconsistency-between-replace-on-an-abstractstring-vs-vector-char/8206>\
**Category:** Internals & Design\
**Created:** [January 6, 2018, 8:01pm UTC](https://discourse.julialang.org/t/inconsistency-between-replace-on-an-abstractstring-vs-vector-char/8206 "2018-01-06T20:01:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [January 6, 2018, 8:01pm UTC](https://discourse.julialang.org/t/inconsistency-between-replace-on-an-abstractstring-vs-vector-char/8206/1 "2018-01-06T20:01:55Z")

</div>

```julia
replace("foobar", "o" => "O", "b" => "B")

```

gives a method error, but

```julia
String(replace(Vector{Char}("foobar"), 'o' => 'O', 'b' => 'B'))

```

returns “fOOBar”.

That means you can’t optimize the replace operation, so that all characters or strings being replaced can be checked once, instead of doing multiple replacement passes on the string, with all the overhead that entails.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [January 6, 2018, 8:34pm UTC](https://discourse.julialang.org/t/inconsistency-between-replace-on-an-abstractstring-vs-vector-char/8206/2 "2018-01-06T20:34:40Z")

</div>

So basically another method needs to be implemented? Everybody is quite busy with breaking changes right now, this kind of feature can be added in 1.x releases.

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [January 6, 2018, 9:25pm UTC](https://discourse.julialang.org/t/inconsistency-between-replace-on-an-abstractstring-vs-vector-char/8206/3 "2018-01-06T21:25:07Z")

</div>

I said nothing about it’s priority - I was just noting it, as something that hopefully will be addressed at some point, having just gotten bitten by it when I had to convert some code with the deprecated `replace(string, txt, rep)` to `replace(string, txt => rep)`.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [January 7, 2018, 11:26am UTC](https://discourse.julialang.org/t/inconsistency-between-replace-on-an-abstractstring-vs-vector-char/8206/4 "2018-01-07T11:26:20Z")

</div>

Actually, @klacru has just made a PR to implement this, we just need to find somebody who has skills and time to review it: [https://github.com/JuliaLang/julia/pull/25396](https://github.com/JuliaLang/julia/pull/25396)

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [January 7, 2018, 12:58pm UTC](https://discourse.julialang.org/t/inconsistency-between-replace-on-an-abstractstring-vs-vector-char/8206/5 "2018-01-07T12:58:37Z")

</div>

I would if I could.
