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
  • 625
  • 2
  • 8
  • 19
  • 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
  • 13
    Whilst this question is definitely a duplicate, who picked the python question? – John Palmer Nov 08 '16 at 10:30

1 Answers1

47

Try built-in int function.

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