Why conversion from string to int leads to a weird value

I am new to F # and I have not been able to find the last element of a number string and convert this element to int. Therefore, if the line was "123", then I would like to go back 3. However, this code:

  let s (a : string) =
      let x = a.[0]
      int x

This returns me 49 when I do s "123". I can’t understand why this is happening. Also, when I entered the string “124”, it still gives me 49. Can someone explain why this is happening and how can I fix it?

+3
source share
2 answers

a.[0] a: '1'. int ASCII. int :

let x = a.Substring(a.Length - 1)
int x

( .Net , F # , .)

+4

, , F # .
: ASCII

int '1' - '1'

, int "1" Int32.Parse("1") Int32.TryParse

.NET Framework

+3

All Articles