Logo

Programming-Idioms

  • Dart
  • Java
  • Java
  • Go
  • Lua
  • C#
  • C#
int i = int.Parse(s);

Throws an error if s can't be converted. int can be replaced with any number data type.
long i = Convert.ToInt64(s);

May throw FormatException and OverflowException.
ToInt32 also exists.
var i = int.parse(s);
int i = Integer.parseInt(s);

Throws NumberFormatException if s does not contain a parsable integer
int i = new Integer(s).intValue();

Throws NumberFormatException if s does not contain a parsable integer
int i = s.chars()
     .map(x -> x - '0')
     .reduce((a, b) -> (a * 10) + b)
     .getAsInt();
Integer i = Integer.valueOf(s, 10);

The second argument in the valueOf method denotes the radix (or base)
import "strconv"
i, err  := strconv.Atoi(s) 

Atoi(s) is shorthand for ParseInt(s, 10, 0). It yields type int.
import "strconv"
i, err := strconv.ParseInt(s, 10, 0)

Radix 10. The third argument 0 means "fit in implementation-specific int". But the result type is always int64.
Don't ignore the potential error err !
i = tonumber(s)
I : Integer := Integer'Value (s);

New implementation...