String을 int로 변환

(String to int에서 넘어옴)
  다른 뜻에 대해서는 정수형 문서를 참조하십시오.
string-int 형 변환
String to int
String to integer
atoi
parseInt
Integer.parseInt

1 같이 보기[ | ]

2 C[ | ]

#include <stdio.h>
#include <stdlib.h>
int main() {
    char *str = "123";
    printf("%d\n", atoi(str)); // 123
    return 0;
}

3 C++[ | ]

#include <iostream>
using namespace std;
int main() {
	string str = "123";
	int n = stoi(str);
	cout << n; // 123	
}

4 C#[ | ]

using System;class Z{static void Main(){

string str = "123";
int i = int.Parse(str);
Console.WriteLine(i); 

}}

5 Go[ | ]

package main

import "fmt"
import "strconv"

func main() {
	var i int
	i, _ = strconv.Atoi("42")
	fmt.Println(i)
}

6 Java[ | ]

class MyClass
{
    public static void main(String[] args) {
        String str = "123";
        int i = Integer.parseInt(str);
        System.out.println(i);
    }
}

7 JavaScript[ | ]

console.log( parseInt('123.45') );  // 123
console.log( parseInt('77') );      // 77

8 Objective-C[ | ]

NSString *s = @"42";
int i = [s intValue];

9 Perl[ | ]

print 0 + '42';       # 42
print int '42,000';   # 42

10 PHP[ | ]

echo intval('42')."\n";            // 42
echo intval('+42')."\n";           // 42
echo intval('-42')."\n";           // -42
echo intval('42,000')."\n";        // 42
echo intval(42)."\n";              // 42
echo intval(4.2)."\n";             // 4
echo intval(042)."\n";             // 34
echo intval('042')."\n";           // 42
echo intval(1e10)."\n";            // 10000000000
echo intval('1e10')."\n";          // 10000000000
echo intval(0x1A)."\n";            // 26
var_dump( 0 + '42' );                 // int(42)
var_dump( intval('hello42') );        // int(0)
var_dump( intval('42hello') );        // int(42)
function string_to_int($str) { return (int)preg_replace('/[^\-\d]*(\-?\d*).*/','$1',$str); }
var_dump( string_to_int( 'The value is 0083.123' ) ); // int(83)

11 Python[ | ]

s = "123"
i = int(s)
print( type(i) )
print( i )

12 Ruby[ | ]

str = "123"
i = str.to_i
print i

13 VB[ | ]

Dim s As String
Dim i As Integer

s = "42"
i = Val(s)