atoi
订阅
atoi (表示 ascii to integer)是把字符串转换成整型数的一个函数,应用在计算机程序和办公软件中。int atoi(const char *nptr) 函数会扫描参数 nptr字符串,会跳过前面的空白字符(例如空格,tab缩进)等。如果 nptr不能转换成 int 或者 nptr为空字符串,那么将返回 0
[1]
。特别注意,该函数要求被转换的字符串是按十进制数理解的。atoi输入的字符串对应数字存在大小限制(与int类型大小有关),若其过大可能报错-1。
展开全文

atoi (表示 ascii to integer)是把字符串转换成整型数的一个函数,应用在计算机程序和办公软件中。int atoi(const char *nptr) 函数会扫描参数 nptr字符串,会跳过前面的空白字符(例如空格,tab缩进)等。如果 nptr不能转换成 int 或者 nptr为空字符串,那么将返回 0
[1]
。特别注意,该函数要求被转换的字符串是按十进制数理解的。atoi输入的字符串对应数字存在大小限制(与int类型大小有关),若其过大可能报错-1。
信息
- 外文名
- atoi
- 头文件
- #include
- 参 数
- 字符串
- 返回值
- int
- 适用语言
- C/C++
atoi简介
atoiint atoi(const char *nptr);_wtoi()
-
atoi
2015-03-16 15:57:20atoipublic int atoi(String str) { int f = 1; int result = 0; boolean start = false; for (int i = 0; i < str.length(); ++i) { if (start) { if (str.charAt(i) < '0' || str.charAt(i) > '9') { break; } else { if (f == 1 && result >= Integer.MAX_VALUE / 10) { if (result > Integer.MAX_VALUE / 10 || (str.charAt(i) - '0') > Integer.MAX_VALUE % 10) { return Integer.MAX_VALUE; } } else if (f == -1 && f * result <= Integer.MIN_VALUE / 10) { if (f * result < Integer.MIN_VALUE / 10 || (str.charAt(i) - '0') > (0 - (Integer.MIN_VALUE % 10))) { return Integer.MIN_VALUE; } } result = result * 10 + (str.charAt(i) - '0'); } } else { if (str.charAt(i) == ' ') { continue; } else if (str.charAt(i) == '-') { f = -1; } else if (str.charAt(i) == '+') { f = 1; } else if (str.charAt(i) >= '0' && str.charAt(i) <= '9') { result = str.charAt(i) - '0'; } else { break; } start=true; } } return f * result; } }
收藏数
10,965
精华内容
4,386
-
【mysql】mysql实现读写分离详细步骤及原理
-
JSP页面缓存的简单实现 (可用于 content-type 为字符类型的JSP页面).zip
-
2020-12-06-DVWA之sql.md
-
VisualSFM_windows_64bit
-
SSH (Struts2+Spring3+Hibernate3) +Proxool_亲测成功 费大劲了.zip
-
Linux与数据库基础
-
Qt项目实战之基于Redis的网络聊天室
-
BUUCTF 11
-
PHP支付宝微信支付配置教程
-
Linux批量下载GNSS测站观测数据脚本
-
proxool教程.zip
-
C++ Primer 2_变量和基本类型(二)
-
SubstancePainter插件开发-基础入门
-
FileConverter-1.2.3-x64-setup
-
visual c++编写.scr屏幕保护程序 黑客帝国屏保 源代码.zip
-
易语言开发通达信DLL公式接口
-
二叉树前序中序后续遍历非递归实现
-
flutter插件调用APP页面、使用原生aar,framework库
-
Selenium3分布式与虚拟化
-
电商设计专业思维