# Remove leading zeros from string to int

**URL:** <https://discourse.julialang.org/t/remove-leading-zeros-from-string-to-int/82048>\
**Category:** General Usage\
**Tags:** strings, parsing, missing-values\
**Created:** [June 1, 2022, 10:48am UTC](https://discourse.julialang.org/t/remove-leading-zeros-from-string-to-int/82048 "2022-06-01T10:48:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Billpete002](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/billpete002/32/35091_2.png) [@Billpete002](https://discourse.julialang.org/u/Billpete002)\
**Post date:** [June 1, 2022, 10:48am UTC](https://discourse.julialang.org/t/remove-leading-zeros-from-string-to-int/82048/1 "2022-06-01T10:48:11Z")

</div>

So my data looks like:

```julia
Stay Duration
string3?
-------
001
012
missing
002

```

What I would like is someway to convert these to Int:

```julia
Stay Duration
Int64
-------
1
12
missing
2

```

My normal method of converting a string to int with missing values doesn’t work:

```julia
IntConverter(x) = Int64(x)
Column_Accepts_Missing = passmissing(IntConverter)
df[!, :stay_dur] = Column_Accepts_Missing.(df[!, :stay_dur])

```

`LoadError: MethodError: no method matching Int64(::String3)`

Is there a way to reverse lpad on a string?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [June 1, 2022, 11:43am UTC](https://discourse.julialang.org/t/remove-leading-zeros-from-string-to-int/82048/2 "2022-06-01T11:43:40Z")

</div>

Getting an integer from a string is parsing, so you should use `parse`:

```julia
julia> parse(Int64, "001")
1

```

In your case you’d have to combine it with passmissing as shown, so:

```julia
julia> passmissing(parse).(Int64, ["001", "012", missing, "002"])
4-element Vector{Union{Missing, Int64}}:
  1
 12
   missing
  2

```
