如何从一串数字中获得数值? [英] How do you get the numerical value from a string of digits?

查看:128
本文介绍了如何从一串数字中获得数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要添加数字字符串的某些部分。

I need to add certain parts of the numerical string.

例如。

036000291453

036000291453

我想将数字添加到奇数编号位置,例如

I want to add the numbers in the odd numbered position so like

0 + 6 + 0 + 2 + 1 + 5等于14。

0+6+0+2+1+5 and have that equal 14.

我尝试了charAt(0)+ charAt(2)等,但是它返回这些字符处的数字,而不是将它们相加。谢谢您的帮助。

I tried the charAt(0)+charAt(2) etc, but it returns the digit at those characters instead of adding them. Thanks for your help.

推荐答案


我尝试了charAt(0)+ charAt(2)等,但它会返回这些
字符处的数字,而不是添加它们。

I tried the charAt(0)+charAt(2) etc, but it returns the digit at those characters instead of adding them.



Character.getNumericValue(string.charAt(0));

这篇关于如何从一串数字中获得数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆