# Idiom #22 Convert string to integer

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

``I : Integer := Integer'Value (s);``
``#include <stdlib.h>``
``i = (int)strtol(s, (char **)NULL, 10);``
``#include <stdlib.h>``
``int i = atoi(s);``
``(def i (Integer. s))``
``(def i (Integer/parseInt s))``
``#include <string>``
``int i = std::stoi(s);``
``````std::string s("123");
int i;
std::from_chars(s.data(), s.data() + s.size(), i, 10);``````
``#include <cstdlib>``
``int i = std::atoi(s);``
``````#include <string>
#include <sstream>``````
``````// Recursive C++ program to find sum of digits
// of a number
#include <bits/stdc++.h>
using namespace std;

// Function to check sum of digit using recursion
int sum_of_digit(int n)
{
if (n == 0)
return 0;
return (n % 10 + sum_of_digit(n / 10));
}

// Driven code
int main()
{
int num = 12345;
int result = sum_of_digit(num);
cout << "Sum of digits in "<< num
<<" is "<<result << endl;
return 0;
}

// THis code is contributed by
// SHUBHAMS``````
``long i = Convert.ToInt64(s);``
``int i = int.Parse(s);``
``import std.conv;``
``auto i = s.to!int;``
``var i = int.parse(s);``
``i = String.to_integer(s)``
``I = list_to_integer(S).``
``read (unit=s,fmt=*) i``
``import "strconv"``
``i, err  := strconv.Atoi(s) ``
``import "strconv"``
``i, err := strconv.ParseInt(s, 10, 0)``
``Integer i = s.toInteger()``
``let i = read s :: Integer``
``const i = +s``
``const i = Number(s);``
``let i = parseInt(s, 10)``
``Integer i = Integer.valueOf(s, 10);``
``int i = Integer.parseInt(s);``
``int i = new Integer(s).intValue();``
``val i = s.toIntOrNull()``
``val i = s.toInt()``
``(setf i (parse-integer s))``
``i = tonumber(s)``
``@import Foundation;``
``int i=s.intValue``
``\$i = intval(\$s, 10);``
``uses SysUtils;``
``i := StrToInt(S);``
``````my \$i = \$s + 0;
``````
``i = int(s)``
``i = s.to_i``
``let i = s.parse::<i32>().unwrap();``
``````let i = match s.parse::<i32>() {
Ok(i) => i,
Err(_e) => -1,
};``````
``let i: i32 = s.parse().unwrap_or(0);``
``s.toInt``
``(define i (string->number s))``
``i := s asInteger.``
``Dim myint As Integer = CInt(("123"))``

programming-idioms.org