# How could we have initialized myphonebook so that it would accept integers as values?

**URL:** <https://discourse.julialang.org/t/how-could-we-have-initialized-myphonebook-so-that-it-would-accept-integers-as-values/16901>\
**Category:** New to Julia\
**Created:** [October 28, 2018, 5:48pm UTC](https://discourse.julialang.org/t/how-could-we-have-initialized-myphonebook-so-that-it-would-accept-integers-as-values/16901 "2018-10-28T17:48:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaxwellGuo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxwellguo/32/5963_2.png) [@MaxwellGuo](https://discourse.julialang.org/u/MaxwellGuo)\
**Post date:** [October 28, 2018, 5:48pm UTC](https://discourse.julialang.org/t/how-could-we-have-initialized-myphonebook-so-that-it-would-accept-integers-as-values/16901/1 "2018-10-28T17:48:09Z")

</div>

myphonebook = Dict(“Jenny” =\> “867-5309”, “Ghostbusters” =\> “555-2368”)

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [October 28, 2018, 5:49pm UTC](https://discourse.julialang.org/t/how-could-we-have-initialized-myphonebook-so-that-it-would-accept-integers-as-values/16901/2 "2018-10-28T17:49:42Z")

</div>

Just use integers instead of strings.

---

<div class="post-metadata">

**Author:** ![oliver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oliver/32/19264_2.png) [@oliver](https://discourse.julialang.org/u/oliver)\
**Post date:** [October 28, 2018, 5:52pm UTC](https://discourse.julialang.org/t/how-could-we-have-initialized-myphonebook-so-that-it-would-accept-integers-as-values/16901/3 "2018-10-28T17:52:28Z")

</div>

Will that always evaluate the `-`

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [October 28, 2018, 8:11pm UTC](https://discourse.julialang.org/t/how-could-we-have-initialized-myphonebook-so-that-it-would-accept-integers-as-values/16901/4 "2018-10-28T20:11:59Z")

</div>

Yes, since an integer cannot contain -.  
What exactly do you want to do?

Maybe you are asking how to remove the - from a string. You can do that eg with the replace function, and then use the parse function to convert it to an integer.

---

<div class="post-metadata">

**Author:** ![jandehaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jandehaan/32/6805_2.png) [@jandehaan](https://discourse.julialang.org/u/jandehaan)\
**Post date:** [October 28, 2018, 8:25pm UTC](https://discourse.julialang.org/t/how-could-we-have-initialized-myphonebook-so-that-it-would-accept-integers-as-values/16901/5 "2018-10-28T20:25:54Z")

</div>

```julia
parse(Int, replace("555-1234", r"\D"=> ""))

```

Feature creep: 😉

```julia
julia> parse(Int, replace("+1(800)555-1234", r"\D"=> ""))
18005551234

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [October 28, 2018, 8:33pm UTC](https://discourse.julialang.org/t/how-could-we-have-initialized-myphonebook-so-that-it-would-accept-integers-as-values/16901/6 "2018-10-28T20:33:17Z")

</div>

```julia
parse(Int, replace("555-1234", "-" => ""))

```

---

<div class="post-metadata">

**Author:** ![Tero\_Frondelius](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tero_frondelius/32/7629_2.png) [@Tero\_Frondelius](https://discourse.julialang.org/u/Tero_Frondelius)\
**Post date:** [October 29, 2018, 5:30am UTC](https://discourse.julialang.org/t/how-could-we-have-initialized-myphonebook-so-that-it-would-accept-integers-as-values/16901/7 "2018-10-29T05:30:42Z")

</div>

Is this your home work assignment?

---

<div class="post-metadata">

**Author:** ![MaxwellGuo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxwellguo/32/5963_2.png) [@MaxwellGuo](https://discourse.julialang.org/u/MaxwellGuo)\
**Post date:** [October 29, 2018, 6:53am UTC](https://discourse.julialang.org/t/how-could-we-have-initialized-myphonebook-so-that-it-would-accept-integers-as-values/16901/8 "2018-10-29T06:53:10Z")

</div>

no, it just is a exercise, i learn it by myself
