# Using \`replace()\` with unicode dot

**URL:** https://discourse.julialang.org/t/using-replace-with-unicode-dot/108133
**Category:** General Usage
**Created:** [December 28, 2023, 2:37pm UTC](https://discourse.julialang.org/t/using-replace-with-unicode-dot/108133 "2023-12-28T14:37:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Brad\_Carman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brad_carman/32/17631_2.png) [@Brad\_Carman](https://discourse.julialang.org/u/Brad_Carman)
#### Post date: [December 28, 2023, 2:37pm UTC](https://discourse.julialang.org/t/using-replace-with-unicode-dot/108133/1 "2023-12-28T14:37:16Z")

</div>

Is there a way to get the “\dot” unicode character to be replaced?

```julia
julia> replace("ẋ′", "ẋ"=>"dx", "′"=>"_p")
"ẋ_p"

```

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [December 28, 2023, 2:50pm UTC](https://discourse.julialang.org/t/using-replace-with-unicode-dot/108133/2 "2023-12-28T14:50:26Z")

</div>

> [@Brad\_Carman](#):
>
> ```julia
> julia> replace("ẋ′", "ẋ"=>"dx", "′"=>"_p")
> "ẋ_p"
> 
> ```

I can’t reproduce your example:

```julia
julia> replace("ẋ′", "ẋ"=>"dx", "′"=>"_p")
"dx_p"

```

However, I have a good guess for what happened on your computer.

I’m guessing that you are having problems due to differences in Unicode normalization. The difficulty is that there are two [“canonically equivalent”](https://en.wikipedia.org/wiki/Unicode_equivalence) ways to express the `"ẋ"` that consist of _different_ sequences of characters. You can can use a single character [U+1E8B](https://www.fileformat.info/info/unicode/char/1e8b/index.htm) `'ẋ'`, _or_ you can use an ordinary ASCII `'x'` followed by [U+0307](https://www.fileformat.info/info/unicode/char/0307/index.htm) “combining dot above”:

```julia
julia> import Unicode

julia> s1 = Unicode.normalize("ẋ", :NFC) # NFC normalization gives the 1-char version
"ẋ"

julia> s2 = Unicode.normalize("ẋ", :NFD) # NFD normalization gives the 2-char version
"ẋ"

julia> s1 == s2
false

julia> collect(s1)
1-element Vector{Char}:
 'ẋ': Unicode U+1E8B (category Ll: Letter, lowercase)

julia> collect(s2)
2-element Vector{Char}:
 'x': ASCII/Unicode U+0078 (category Ll: Letter, lowercase)
 '̇': Unicode U+0307 (category Mn: Mark, nonspacing)

```

Probably you are using the NFC version in one place and an NFD version in another. Either be consistent in how you enter `"ẋ"` or explicitly call `Unicode.normalize` before doing the `replace` call.

I’m guessing that the reason your example worked for me is that, as @mbauman commented [in another thread](https://discourse.julialang.org/t/string-indices-byte-indexing-feels-wrong/107164/11), some browsers automatically normalize Unicode when you paste into their text-entry box to post on discourse.

PS. Note that this is not in any way specific to Julia. The same issue of multiple representations for the “same” string appears in _any_ language supporting Unicode text.

---

<div class="post-metadata">

### Author: ![Brad\_Carman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brad_carman/32/17631_2.png) [@Brad\_Carman](https://discourse.julialang.org/u/Brad_Carman)
#### Post date: [December 28, 2023, 2:53pm UTC](https://discourse.julialang.org/t/using-replace-with-unicode-dot/108133/3 "2023-12-28T14:53:46Z")

</div>

Thanks! I knew I would learn something new with this question 😄
