22

How do i convert from string to int in F#?

As an example i'd like to pass let someString = "123 to let someInt = 123 I cant really find any parse methods that work for me.. This question is not about parsing from int to String, but string to int. Not duplicate of a related question. Any ideas?

Thanks in advance

Anders Lassen
  • 615
  • 2
  • 8
  • 20
  • 3
    The easiest way is to just use the `int` function. Apart from that, everything that works elsewhere in .NET is valid in F# as well, such as `System.Int32.Parse()`. – TeaDrivenDev Nov 07 '16 at 22:18
  • 14
    Whilst this question is definitely a duplicate, who picked the python question? – John Palmer Nov 08 '16 at 10:30
  • "This question is not about parsing from into to String" <- you don't "parse" an `int` to a `string`, you parse a `string` to `int` – Adam Jul 05 '23 at 20:58

1 Answers1

51

Try built-in int function.

let someString = "123" 
let someInt = someString |> int // someInt now contains 123 int value
Dzoukr
  • 1,094
  • 1
  • 13
  • 17