Logo

Programming-Idioms

Extract the integer value i from its string representation s (in radix 10)
Implementation
Go

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Go implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
int i = Integer.parseInt(s);
int i = new Integer(s).intValue();
i = s.to_i
import "strconv"
i, err  := strconv.Atoi(s) 
#include <cstdlib>
int i = std::atoi(s);
var i = int.parse(s);
i = int(s)
long i = Convert.ToInt64(s);
my $i = $s + 0;
let i = s.parse::<i32>().unwrap();
$i = intval($s, 10);
#include <stdlib.h>
int i = atoi(s);
import std.conv;
auto i = s.to!int;
let i: i32 = s.parse().unwrap_or(0);
uses SysUtils;
i := StrToInt(S);
let i = read s :: Integer
(def i (Integer/parseInt s))
i = String.to_integer(s)
I = list_to_integer(S).
let i = match s.parse::<i32>() {
  Ok(i) => i,
  Err(_e) => -1,
};
i = tonumber(s)
I : Integer := Integer'Value (s);
s.toInt
let i = parseInt(s, 10)
(define i (string->number s))
#include <string>
int i = std::stoi(s);
(setf i (parse-integer s))
read (unit=s,fmt=*) i
val i = s.toInt()
val i = s.toIntOrNull()
const i = Number(s);
#include <string>
#include <sstream>
std::stringstream ss(str);
int i;
ss >> i;
Dim myint As Integer = CInt(("123"))
const i = +s
int i = int.Parse(s);
std::string s("123");
int i;
std::from_chars(s.data(), s.data() + s.size(), i, 10);
(def i (Integer. s))
@import Foundation;
int i=s.intValue
#include <stdlib.h>
i = (int)strtol(s, (char **)NULL, 10);
i := s asInteger.
Integer i = Integer.valueOf(s, 10);
Integer i = s.toInteger()