【问题标题】:How to get the 2nd and 3rd character of a String as Integer - C89如何将字符串的第二个和第三个字符作为整数 - C89
【发布时间】:2020-05-22 04:27:09
【问题描述】:

所以如果我有一个字符串

char string[4];
string = "A10";

我怎样才能得到 10 作为整数。 我尝试使用它自己获得 10,但它没有用。

char string[4];
char string2[2];
string = "A10";
string2[0] = string[1];
string2[1] = string[2];

我不需要担心 A,我知道如何得到它,我需要能够得到 10 作为整数。

【问题讨论】:

    标签: string parsing type-conversion integer c89


    【解决方案1】:

    在java中你可以使用下面的代码将字符串转换为整数,

    int i=Integer.parseInt(s2); 
    

    欲了解更多信息,请查看本网站, https://www.javatpoint.com/java-string-to-int

    【讨论】:

    • C89 中的标签和注释
    猜你喜欢
    • 1970-01-01
    • 2021-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-21
    • 1970-01-01
    • 2016-03-29
    • 2014-06-08
    相关资源
    最近更新 更多