Logo

Programming-Idioms

  • Lisp
  • C++
  • PHP
  • Java
  • Python
  • JS
  • Clojure
(def i (Integer. s))
(def i (Integer/parseInt s))
(setf i (parse-integer s))
#include <cstdlib>
int i = std::atoi(s);

s is a char*
std::string s("123");
int i;
std::from_chars(s.data(), s.data() + s.size(), i, 10);
#include <string>
#include <sstream>
std::stringstream ss(str);
int i;
ss >> i;
#include <string>
int i = std::stoi(s);
$i = intval($s, 10);
Integer i = Integer.valueOf(s, 10);

The second argument in the valueOf method denotes the radix (or base)
int i = s.chars()
     .map(x -> x - '0')
     .reduce((a, b) -> (a * 10) + b)
     .getAsInt();
int i = new Integer(s).intValue();

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

Throws NumberFormatException if s does not contain a parsable integer
i = int(s)
const i = +s
const i = Number(s);
let i = parseInt(s, 10)

parseInt(string, radix);
The radix is an integer between 2 and 36.
I : Integer := Integer'Value (s);

New implementation...