# Division for Strings

**URL:** https://discourse.julialang.org/t/division-for-strings/22381
**Category:** Internals & Design
**Created:** [March 26, 2019, 10:30pm UTC](https://discourse.julialang.org/t/division-for-strings/22381 "2019-03-26T22:30:17Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![asprionj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asprionj/32/6856_2.png) [@asprionj](https://discourse.julialang.org/u/asprionj)
#### Post date: [March 26, 2019, 10:30pm UTC](https://discourse.julialang.org/t/division-for-strings/22381/1 "2019-03-26T22:30:17Z")

</div>

Just had this silly idea when trying to prepend a string to an existing one. When appending, one can do:

```julia
a = "1"
a *= ",2" # "1,2"

```

Now, we could use division for prepending:

```julia
a = "1"
a /= "0," # "0,1"

```

What do you think? Is this any good?

---

<div class="post-metadata">

### Author: ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)
#### Post date: [March 26, 2019, 10:35pm UTC](https://discourse.julialang.org/t/division-for-strings/22381/2 "2019-03-26T22:35:15Z")

</div>

`/` doesn’t hold general rule that:

```julia
a *= ",2"  
# same as
a = a * ",2"

```

instead you get:

```julia
a /= "0,"  
# same as
a = "0," * a

```

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [March 26, 2019, 10:40pm UTC](https://discourse.julialang.org/t/division-for-strings/22381/3 "2019-03-26T22:40:26Z")

</div>

If we give division a meaning for strings, it’d likely be one that’s compatible with whatever `*` means for strings: [https://github.com/JuliaLang/julia/pull/13411](https://github.com/JuliaLang/julia/pull/13411). In other words, it’d remove common subsequences in contrast to how `*` appends subsequences.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [March 27, 2019, 2:54am UTC](https://discourse.julialang.org/t/division-for-strings/22381/4 "2019-03-27T02:54:55Z")

</div>

I still don’t entirely hate that. It should error if the prefix/suffix doesn’t match.

---

<div class="post-metadata">

### Author: ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)
#### Post date: [March 27, 2019, 6:13am UTC](https://discourse.julialang.org/t/division-for-strings/22381/5 "2019-03-27T06:13:40Z")

</div>

Why not use

```julia
a = "1"
a =* "0." # same as a = "0." * a

```

This way you can have consistency

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [March 27, 2019, 6:38am UTC](https://discourse.julialang.org/t/division-for-strings/22381/6 "2019-03-27T06:38:41Z")

</div>

Because there is no `=*`. There is no `*=` either in the sense of having a primitive, it just expands to `*` and assignment. Eg

```julia
julia> Meta.@lower a *= 1
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope'
1 ─ %1 = a * 1
│ a = %1
└── return %1
))))

```

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [March 27, 2019, 6:52pm UTC](https://discourse.julialang.org/t/division-for-strings/22381/7 "2019-03-27T18:52:41Z")

</div>

> [@asprionj](#):
>
> What do you think? Is this any good?

Being able to prepend a string in this way is very useful but division is entirely the wrong operator for the functionality. It’s easy enough to try out in your own code though.

```julia
julia> Base.:/(a::AbstractString, b::AbstractString) = b * a

julia> a = "a"
"a"

julia> a /= "b"
"ba"

```
