# Convert a string to an integer?

**URL:** <https://forum.elixirforum.com/t/convert-a-string-to-an-integer/4784>\
**Category:** Questions\
**Tags:** how-to-question\
**Created:** [April 25, 2017, 9:35pm UTC](https://forum.elixirforum.com/t/convert-a-string-to-an-integer/4784 "2017-04-25T21:35:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![tyro](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/t/858c86/32.png) [@tyro](https://forum.elixirforum.com/u/tyro)\
**Post date:** [April 25, 2017, 9:41pm UTC](https://forum.elixirforum.com/t/convert-a-string-to-an-integer/4784/2 "2017-04-25T21:41:40Z")

</div>

Hi there!

To convert a string to an integer you can use `String.to_integer/1` e.g.

```elixir
int = String.to_integer("1")

```

When it comes to user input you might also want to remove whitespace first which you can do with `String.trim/1`.

Hope that helps!

---

_[View the full topic](https://forum.elixirforum.com/t/convert-a-string-to-an-integer/4784)._
